Skip to content

Detect shells ending in .exe (for Windows/Cygwin) #17431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/2 Fixes/17426.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve pattern matching for shell detection on Windows.
(thanks [Erik Demaine](https://github.com/edemaine/))
4 changes: 2 additions & 2 deletions src/client/common/terminal/shellDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export class ShellDetector {
/**
* Logic is as follows:
* 1. Try to identify the type of the shell based on the name of the terminal.
* 2. Try to identify the type of the shell based on the usettigs in VSC.
* 2. Try to identify the type of the shell based on the settings in VSC.
* 3. Try to identify the type of the shell based on the user environment (OS).
* 4. If all else fail, use defaults hardcoded (cmd for windows, bash for linux & mac).
* More information here See solution here https://github.com/microsoft/vscode/issues/74233#issuecomment-497527337
* More information here: https://github.com/microsoft/vscode/issues/74233#issuecomment-497527337
*
* @param {Terminal} [terminal]
* @returns {TerminalShellType}
Expand Down
20 changes: 12 additions & 8 deletions src/client/common/terminal/shellDetectors/baseShellDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ When identifying the shell use the following algorithm:

// Types of shells can be found here:
// 1. https://wiki.ubuntu.com/ChangingShells
const IS_GITBASH = /(gitbash.exe$)/i;
const IS_BASH = /(bash.exe$|bash$)/i;
const IS_WSL = /(wsl.exe$)/i;
const IS_GITBASH = /(gitbash$)/i;
const IS_BASH = /(bash$)/i;
const IS_WSL = /(wsl$)/i;
const IS_ZSH = /(zsh$)/i;
const IS_KSH = /(ksh$)/i;
const IS_COMMAND = /(cmd.exe$|cmd$)/i;
const IS_POWERSHELL = /(powershell.exe$|powershell$)/i;
const IS_POWERSHELL_CORE = /(pwsh.exe$|pwsh$)/i;
const IS_COMMAND = /(cmd$)/i;
const IS_POWERSHELL = /(powershell$)/i;
const IS_POWERSHELL_CORE = /(pwsh$)/i;
const IS_FISH = /(fish$)/i;
const IS_CSHELL = /(csh$)/i;
const IS_TCSHELL = /(tcsh$)/i;
Expand Down Expand Up @@ -54,17 +54,21 @@ export abstract class BaseShellDetector implements IShellDetector {
terminal?: Terminal,
): TerminalShellType | undefined;
public identifyShellFromShellPath(shellPath: string): TerminalShellType {
// Remove .exe extension so shells can be more consistently detected
// on Windows (including Cygwin).
const basePath = shellPath.replace(/\.exe$/, '');

const shell = Array.from(detectableShells.keys()).reduce((matchedShell, shellToDetect) => {
if (matchedShell === TerminalShellType.other) {
const pat = detectableShells.get(shellToDetect);
if (pat && pat.test(shellPath)) {
if (pat && pat.test(basePath)) {
return shellToDetect;
}
}
return matchedShell;
}, TerminalShellType.other);

traceVerbose(`Shell path '${shellPath}'`);
traceVerbose(`Shell path '${shellPath}', base path '${basePath}'`);
traceVerbose(`Shell path identified as shell '${shell}'`);
return shell;
}
Expand Down