How to run Visual Studio Code on Mac OSX
EDIT: You can just do this from Visual Studio Code now.
Terminal
Currently, there isn’t an automatic method for doing this, but with a little code in your ~/.bash_profile file, you can configure it.
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
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
Zsh
Using Visual Studio Code on your Mac, but can’t call it from Zsh?
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 ]]
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
About Kevin
Kevin Griffin has been running production .NET applications and teaching developers for over two decades. A 16-time Microsoft MVP specializing in ASP.NET Core and Azure, Kevin brings real-world experience from his own SaaS products alongside his consulting work at Swift Kick. He's hosted the Hampton Roads .NET User Group since 2009 and founded RevolutionVA, the nonprofit behind Hampton Roads DevFest. Kevin's talks blend hard-won lessons from production systems with practical advice you can use Monday morning.
Categories