Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinayakkulkarni/f21b984c62711fc37415702384592e6e to your computer and use it in GitHub Desktop.
Save vinayakkulkarni/f21b984c62711fc37415702384592e6e to your computer and use it in GitHub Desktop.
launch_visual_studio_code_from_terminal

Launch Visual Studio Code from the macOS Terminal

Visual Studio Code ships with a CLI called code. This utility is hidden in the following folder (assuming you installed Visual Studio Code in /Applications like normal folk. If this following line opens Visual Studio Code for you, then bingo, you're ready.

open /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code

You can find more (official) details about code here

Installation

The official documentation I linked to above recommends creating a ~/bin folder (in your home directory). That's weird, I don't recall ever being asked to do that on OS X since most people install binaries within /usr/local/bin which – if you're a developer – is likely to already have tons of other binaries.

ln -s /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code /usr/local/bin/vscode

This will simply create a symlink called vscode (remember, we like names that don't suck to type 500 times a day) between the code binary stashed in the Visual Studio Application package, and a folder where your system usually looks for binaries to execute (launch). Think of it as a wormhole of awesome.

Now let's do a check to see if everything will run smoothly. Enter this:

open ~/.bash_profile

You should see at the top of the file a line that starts with:

export PATH=

This contains all the directories that will be looked into for executable binaries when you type a command in Terminal. Since we create a symlink to code called vscode in the /usr/local/bin directory let's check if this directory is listed on that same line.

If it is, perfect. Let's keep going. If not, simply add it like this and save the file:

export PATH=/usr/local/bin:(...)

Note: The "(...)" in this example represents other folders that would be listed on the same line and separated by a colon.

If you had to add /usr/local/bin to your PATH, run the following command before continuing:

source ~/.bash_profile

This will reload your .bash_profile with the newly added directory.

Testing

Open a Terminal window and run:

vscode filename (replace "filename" by an actual file name)

or

vscode foldername (replace "foldername" by an actual folder name)

or even

vscode . (to open the entire current directory)

Conclusion

Now you don't need to get out of Terminal to simply open a file or a folder, you didn't have to add an "alias" or yet another bin directory to your .bash_profile which you would have needed with the official instructions given by the Visual Studio team.

Have fun, Visual Studio Code is a great editor showing a lot of promise.

@vinayakkulkarni
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment