My Technical Notes

Wednesday, 7 June 2017

A Visual Studio Code Shell Wrapper in PowerShell

Visual Studio Code comes with a `code.cmd` shell wrapper:


@echo off
setlocal
set VSCODE_DEV=
set ELECTRON_RUN_AS_NODE=1
call "%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" %*
endlocal

Here is a PowerShell version of this code:


& {
    $before_vsCode_dev = $env:VSCODE_DEV;
    $before_electron = $env:ELECTRON_RUN_AS_NODE;
    
    $env:VSCODE_DEV = "";
    $env:ELECTRON_RUN_AS_NODE = "1";
    
    $binDir = Split-Path (Get-Command code.cmd).Definition;
    
    & "$binDir\..\Code.exe" "$binDir\..\resources\app\out\cli.js" @args
    
    $env:VSCODE_DEV = $before_vsCode_dev;
    $env:ELECTRON_RUN_AS_NODE = $before_electron;
} @args

No comments: