Skip to content
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

Support Windows Subsystem for Linux #10

Merged
merged 1 commit into from
Jan 2, 2018
Merged
Changes from all 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
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();
}