diff --git a/src/extension.ts b/src/extension.ts index 312eb02..18e86f9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -39,43 +39,6 @@ function showButtons() { }); } -function getTerminalConfig(): {shellPath: string | undefined, shellArgs: string | string[] | undefined} { - const shellConfig = vscode.workspace.getConfiguration('terminal.integrated.shell'); - const shellArgsConfig = vscode.workspace.getConfiguration('terminal.integrated.shellArgs'); - let osSection: string | undefined; - if (process.platform === "win32") { - osSection = 'windows'; - } else if (process.platform === "darwin") { - osSection = 'osx'; - } else if (process.platform === "linux") { - osSection = 'linux'; - } - if (osSection) { - return { - shellPath: shellConfig.get(osSection) || undefined, - shellArgs: shellArgsConfig.get(osSection) || undefined - }; - } else { - return { - shellPath: undefined, - shellArgs: undefined - }; - } -} - -const POWERSHELLS = [/(powershell.exe$|powershell$)/i, /(pwsh.exe$|pwsh$)/i]; - -type ShellKind = 'powershell' | 'other'; - -function identifyShell(shellPath: string): ShellKind { - for (let pat of POWERSHELLS) { - if (pat.test(shellPath)) { - return 'powershell'; - } - } - return 'other'; -} - async function startTerminal( existing: vscode.Terminal | undefined, name: string, cmd: string ): Promise { @@ -83,29 +46,18 @@ async function startTerminal( existing.dispose(); } const terminalOptions: vscode.TerminalOptions = {name: name}; - let cmdPrefix = ""; if (isWindows) { - const shellCfg = getTerminalConfig(); - const shellPath = shellCfg.shellPath; - const shellArgs = shellCfg.shellArgs; - if (shellPath) { - terminalOptions.shellPath = shellPath; - if (shellArgs) { - terminalOptions.shellArgs = shellArgs; - } - if (identifyShell(shellPath) === "powershell") { - cmdPrefix = "& "; - } - } else { - // powershell is the default - cmdPrefix = "& "; - } + // We don't know which shell will be used by default. + // If PowerShell is the default, we need to prefix the command with "& ". + // Otherwise, the prefix is not allowed and results in a syntax error. + // -> Just force cmd.exe. + terminalOptions.shellPath = "cmd.exe"; } const terminal = vscode.window.createTerminal(terminalOptions); // Sometimes the terminal takes some time to start up before it can start accepting input. await new Promise((resolve) => setTimeout(resolve, 100)); terminal.show(false); // focus the terminal - terminal.sendText(cmdPrefix + cmd); + terminal.sendText(cmd); return terminal; }