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.

function code {  
    if [[ $# = 0 ]]
        open -a "Visual Studio Code"
        local argPath="$1"
        [[ $1 = /* ]] && argPath="$1" || argPath="$PWD/${1#./}"
        open -a "Visual Studio Code" "$argPath"

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

I really hope you enjoyed this post, and I especially hope you learned something new today because of it.

If you don't mind, I would love to send you more great knowledge packed emails (promise no more than 1 per week!).

Sign up below!

Full Name
Email *
email marketing by activecampaign
comments powered by Disqus