From 704cd065144b38d3b1cba7191798b7072a64b5a1 Mon Sep 17 00:00:00 2001 From: Jamal Carvalho Date: Wed, 15 Jun 2022 20:13:38 +0000 Subject: [PATCH] src/goEnvironmentStatus.ts: use vscode.env.shell to determine shell type When the callback for vscode.window.onDidOpenTerminal is called terminal.name is typically unset and can change during launch. The API for vscode.env.shell has stabilized so we can use that value instead. Removed support for windows shells, as this code path only runs on macOS. Fixes golang/vscode-go#2283. Change-Id: I62517812ddc194393ed36c89dc6fd13f4ef77b71 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/412314 Reviewed-by: Hyang-Ah Hana Kim Run-TryBot: Jamal Carvalho TryBot-Result: kokoro --- src/goEnvironmentStatus.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/goEnvironmentStatus.ts b/src/goEnvironmentStatus.ts index c770bb190b..7902b844c9 100644 --- a/src/goEnvironmentStatus.ts +++ b/src/goEnvironmentStatus.ts @@ -374,17 +374,13 @@ export async function updateIntegratedTerminal(terminal: vscode.Terminal): Promi // append the goroot to the beginning of the PATH so it takes precedence // TODO: add support for more terminal names - // this assumes all non-windows shells are bash-like. - if (terminal.name.toLowerCase() === 'cmd') { - terminal.sendText(`set PATH=${gorootBin};%Path%`, true); - terminal.sendText('cls'); - } else if (['powershell', 'pwsh'].includes(terminal.name.toLowerCase())) { + if (vscode.env.shell.search(/(powershell|pwsh)$/i) !== -1) { terminal.sendText(`$env:Path="${gorootBin};$env:Path"`, true); terminal.sendText('clear'); - } else if (terminal.name.toLowerCase() === 'fish') { + } else if (vscode.env.shell.search(/fish$/i) !== -1) { terminal.sendText(`set -gx PATH ${gorootBin} $PATH`); terminal.sendText('clear'); - } else if (['bash', 'sh', 'zsh', 'ksh'].includes(terminal.name.toLowerCase())) { + } else if (vscode.env.shell.search(/\/(bash|sh|zsh|ksh)$/i) !== -1) { terminal.sendText(`export PATH=${gorootBin}:$PATH`, true); terminal.sendText('clear'); }