How to run Visual Studio Code from Zsh on Mac OSX

EDIT: You can just do this from Visual Studio Code now.

Using Visual Studio Code on your Mac, but can’t call it from Zsh?

Using Terminal? Go here

Currently, there isn’t an automatic method for doing this, but with a little code in your .zshrc file, you can configure it.

1
2
3
4
5
6
7
8
9
10
function code {
if [[ $# = 0 ]]
then
open -a "Visual Studio Code"
else
local argPath="$1"
[[ $1 = /* ]] && argPath="$1" || argPath="$PWD/${1#./}"
open -a "Visual Studio Code" "$argPath"
fi
}

Then from Terminal you can type:

code – opens Visual Studio Code
code . – opens current directory in Visual Studio Code
code somefile – opens somefile in Visual Studio Code

Originally published on 2015-05-07 in Development

Enjoy this article? Let's keep in touch

I really appreciate you taking the time out of your schedule to read this post. I like to keep my friends updated on new articles and also spawn discussions here and there.

If you'd like to keep in touch, please subscribe below. And I promise, no more than 1 email per week (if even that).