Skip to content

Commit

Permalink
Merge pull request #10 from dyong0/fix/wsl-support
Browse files Browse the repository at this point in the history
Support Windows Subsystem for Linux
  • Loading branch information
Tyriar authored Jan 2, 2018
2 parents cc20d67 + 80291e6 commit 6c97420
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ 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);
terminal.sendText(`cd "${dir}"`);
Expand All @@ -30,4 +36,21 @@ export function activate(context: vscode.ExtensionContext) {
}

export function deactivate() {
}

function isWslBash(terminalSettings) {
const windowsShellPath = terminalSettings.integrated.shell.windows;

if(!windowsShellPath) {
return false;
}

// 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');

// %windir% can give WINDOWS instead of Windows
return windowsShellPath.toLowerCase() === expectedWslBashPath.toLowerCase();
}

0 comments on commit 6c97420

Please sign in to comment.