Skip to content

Commit

Permalink
src/goEnvironmentStatus.ts: use vscode.env.shell to determine shell type
Browse files Browse the repository at this point in the history
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 #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>
  • Loading branch information
jamalc committed Jun 16, 2022
1 parent c31bc21 commit 704cd06
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/goEnvironmentStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit 704cd06

Please sign in to comment.