DEV Community

Cover image for WSL2 launch VSCODE (quick tip)
Ricardo de Arruda
Ricardo de Arruda

Posted on

WSL2 launch VSCODE (quick tip)

If you are using WSL2 and want to launch the vscode from your Windows bin from WSL linux terminal, you can use this simple gist:

#!/usr/bin/env bash

username="Your Windows User Name"
bin_path="/mnt/c/Users/$username/AppData/Local/Programs/Microsoft\ VS\ Code/bin/code"

if [ $# -eq 0  ]; then
  eval "$bin_path -add $(pwd)"
  eval "$bin_path -add $1"

If you don't want to hard-code your username:

username=$(/mnt/c/Windows/System32/cmd.exe /c 'echo %username%' |& tail -1)

And now you can user the command code to open the folder or code filename to open file, as the vscode CLI.

Be also sure to have Remote-WSl extension installed.

Now save at /usr/local/bin/ or anywhere in your PATH for global access.

Top comments (0)