|
1 | | -import { Terminal } from 'vscode'; |
| 1 | +import { Terminal, TerminalShellType as TerminalShellTypeVscode } from 'vscode'; |
2 | 2 | import { isWindows } from '../../managers/common/utils'; |
3 | 3 | import * as os from 'os'; |
4 | 4 | import { vscodeShell } from '../../common/vscodeEnv.apis'; |
@@ -32,22 +32,24 @@ const IS_NUSHELL = /(nu$)/i; |
32 | 32 | const IS_XONSH = /(xonsh$)/i; |
33 | 33 |
|
34 | 34 | type KnownShellType = Exclude<TerminalShellType, TerminalShellType.unknown>; |
35 | | -const detectableShells = new Map<KnownShellType, RegExp>(unsafeEntries({ |
36 | | - [TerminalShellType.powershell]: IS_POWERSHELL, |
37 | | - [TerminalShellType.gitbash]: IS_GITBASH, |
38 | | - [TerminalShellType.bash]: IS_BASH, |
39 | | - [TerminalShellType.wsl]: IS_WSL, |
40 | | - [TerminalShellType.zsh]: IS_ZSH, |
41 | | - [TerminalShellType.ksh]: IS_KSH, |
42 | | - [TerminalShellType.commandPrompt]: IS_COMMAND, |
43 | | - [TerminalShellType.fish]: IS_FISH, |
44 | | - [TerminalShellType.tcshell]: IS_TCSHELL, |
45 | | - [TerminalShellType.cshell]: IS_CSHELL, |
46 | | - [TerminalShellType.nushell]: IS_NUSHELL, |
47 | | - [TerminalShellType.powershellCore]: IS_POWERSHELL_CORE, |
48 | | - [TerminalShellType.xonsh]: IS_XONSH, |
49 | | -// This `satisfies` makes sure all shells are covered |
50 | | -} satisfies Record<KnownShellType, RegExp>)); |
| 35 | +const detectableShells = new Map<KnownShellType, RegExp>( |
| 36 | + unsafeEntries({ |
| 37 | + [TerminalShellType.powershell]: IS_POWERSHELL, |
| 38 | + [TerminalShellType.gitbash]: IS_GITBASH, |
| 39 | + [TerminalShellType.bash]: IS_BASH, |
| 40 | + [TerminalShellType.wsl]: IS_WSL, |
| 41 | + [TerminalShellType.zsh]: IS_ZSH, |
| 42 | + [TerminalShellType.ksh]: IS_KSH, |
| 43 | + [TerminalShellType.commandPrompt]: IS_COMMAND, |
| 44 | + [TerminalShellType.fish]: IS_FISH, |
| 45 | + [TerminalShellType.tcshell]: IS_TCSHELL, |
| 46 | + [TerminalShellType.cshell]: IS_CSHELL, |
| 47 | + [TerminalShellType.nushell]: IS_NUSHELL, |
| 48 | + [TerminalShellType.powershellCore]: IS_POWERSHELL_CORE, |
| 49 | + [TerminalShellType.xonsh]: IS_XONSH, |
| 50 | + // This `satisfies` makes sure all shells are covered |
| 51 | + } satisfies Record<KnownShellType, RegExp>), |
| 52 | +); |
51 | 53 |
|
52 | 54 | function identifyShellFromShellPath(shellPath: string): TerminalShellType { |
53 | 55 | // Remove .exe extension so shells can be more consistently detected |
@@ -122,8 +124,38 @@ function identifyShellFromSettings(): TerminalShellType { |
122 | 124 | return shellPath ? identifyShellFromShellPath(shellPath) : TerminalShellType.unknown; |
123 | 125 | } |
124 | 126 |
|
| 127 | +function fromShellTypeApi(terminal: Terminal): TerminalShellType { |
| 128 | + switch (terminal.state.shellType) { |
| 129 | + case TerminalShellTypeVscode.Sh: |
| 130 | + case TerminalShellTypeVscode.Bash: |
| 131 | + return TerminalShellType.bash; |
| 132 | + case TerminalShellTypeVscode.Fish: |
| 133 | + return TerminalShellType.fish; |
| 134 | + case TerminalShellTypeVscode.Csh: |
| 135 | + return TerminalShellType.cshell; |
| 136 | + case TerminalShellTypeVscode.Ksh: |
| 137 | + return TerminalShellType.ksh; |
| 138 | + case TerminalShellTypeVscode.Zsh: |
| 139 | + return TerminalShellType.zsh; |
| 140 | + case TerminalShellTypeVscode.CommandPrompt: |
| 141 | + return TerminalShellType.commandPrompt; |
| 142 | + case TerminalShellTypeVscode.GitBash: |
| 143 | + return TerminalShellType.gitbash; |
| 144 | + case TerminalShellTypeVscode.PowerShell: |
| 145 | + return TerminalShellType.powershellCore; |
| 146 | + case TerminalShellTypeVscode.NuShell: |
| 147 | + return TerminalShellType.nushell; |
| 148 | + default: |
| 149 | + return TerminalShellType.unknown; |
| 150 | + } |
| 151 | +} |
| 152 | + |
125 | 153 | export function identifyTerminalShell(terminal: Terminal): TerminalShellType { |
126 | | - let shellType = identifyShellFromTerminalName(terminal); |
| 154 | + let shellType = fromShellTypeApi(terminal); |
| 155 | + |
| 156 | + if (shellType === TerminalShellType.unknown) { |
| 157 | + shellType = identifyShellFromTerminalName(terminal); |
| 158 | + } |
127 | 159 |
|
128 | 160 | if (shellType === TerminalShellType.unknown) { |
129 | 161 | shellType = identifyShellFromSettings(); |
|
0 commit comments