Skip to content

Commit

Permalink
Support Windows Subsystem for Linux
Browse files Browse the repository at this point in the history
Fixes #5

It determines the directory path by checking Windows shell path.
The shell paths are listed in the official VS Code page.
https://code.visualstudio.com/docs/editor/integrated-terminal
  • Loading branch information
dyong1 committed Jan 1, 2018
1 parent cc20d67 commit eb9c7dc
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 eb9c7dc

Please sign in to comment.