From 98db08315afd7e68f8b2cfc777afce167eb778c0 Mon Sep 17 00:00:00 2001 From: saaketp Date: Wed, 3 Jan 2018 12:24:17 +0530 Subject: [PATCH] Change drive letter before cd in case of cmd.exe Fixes #4 Check for cmd.exe in config, similar to wsl bash check and send 1st two characters of the path before doing cd to change drive letter. --- src/extension.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 65d4146..8792e89 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -22,13 +22,18 @@ export function activate(context: vscode.ExtensionContext) { let dir = path.dirname(uri.fsPath); - if(isWslBash(vscode.workspace.getConfiguration('terminal'))) { - // c:\workspace\foo to /mnt/c/workspace/foo - dir = dir.replace(/(\w):/, '/mnt/$1').replace(/\\/g, '/') - } - let terminal = vscode.window.createTerminal(); terminal.show(false); + + switch(kindOfShell(vscode.workspace.getConfiguration('terminal'))) { + case "wslbash": + // c:\workspace\foo to /mnt/c/workspace/foo + dir = dir.replace(/(\w):/, '/mnt/$1').replace(/\\/g, '/') + break; + case "cmd": + terminal.sendText(dir.slice(0,2)); + } + terminal.sendText(`cd "${dir}"`); }); @@ -38,19 +43,21 @@ export function activate(context: vscode.ExtensionContext) { export function deactivate() { } -function isWslBash(terminalSettings) { +function kindOfShell(terminalSettings) { const windowsShellPath = terminalSettings.integrated.shell.windows; if(!windowsShellPath) { - return false; + return undefined; } // Detect WSL bash according to the implementation of VS Code terminal. // For more details, refer to https://goo.gl/AuwULb const is32ProcessOn64Windows = process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432'); const system32 = is32ProcessOn64Windows ? 'Sysnative' : 'System32'; - const expectedWslBashPath = path.join(process.env.windir, system32, 'bash.exe'); + var shellKindByPath = {} + shellKindByPath[path.join(process.env.windir, system32, 'bash.exe').toLowerCase()] = "wslbash"; + shellKindByPath[path.join(process.env.windir, system32, 'cmd.exe').toLowerCase()] = "cmd"; // %windir% can give WINDOWS instead of Windows - return windowsShellPath.toLowerCase() === expectedWslBashPath.toLowerCase(); + return shellKindByPath[windowsShellPath.toLowerCase()] } \ No newline at end of file