DEV Community

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

Posted on

3 2

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)"
else
  eval "$bin_path -add $1"
fi

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay