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 <hyangah@gmail.com> Run-TryBot: Jamal Carvalho <jamal@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com>
diff --git a/src/goEnvironmentStatus.ts b/src/goEnvironmentStatus.ts index c770bb1..7902b84 100644 --- a/src/goEnvironmentStatus.ts +++ b/src/goEnvironmentStatus.ts
@@ -374,17 +374,13 @@ // 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'); }