I'd like to run / open Visual Studio Code from the Mac OSX Terminal by running this command code .
. I found instructions here:
https://code.visualstudio.com/Docs/setup
Apparently I need to include this in my .bashrc
file, so I did, but to no avail.
code () {
if [[ $# = 0 ]]
then
open -a "Visual Studio Code"
else
[[ $1 = /* ]] && F="$1" || F="$PWD/${1#./}"
open -a "Visual Studio Code" --args "$F"
fi
}
I edited the .bashrc
file here:
~/.bashrc
which points to /Users/username/.bashrc
Which .bashrc
should I be editing?
If you are on Mac OSX Maverick, it's
~/.bash_profile
not~/.bashrc
Try putting the code in there, close the terminal and then try again. Should be working
For Mac you can do : View > Command Palette > Shell command > "install code command in path". I'd assume there would be something similar for other OS's. After I do
and it tells me it put it in /usr/local/bin
I just want to pull out Benjamin Pasero's answer from inside his comment as it seems the best solution. It is the tip given on the Setting up Visual Studio Code page where it says ...
If you want to run VS Code from the terminal, append the following to your ~/.bash_profile file (~/.zshrc in case you use zsh).
Now, you can simply type
code .
in any folder to start editing files in that folder. [Orcode test.txt
to go to work on thetest.txt
file]I simply created a file called code:
Make it executable:
Then put that in /usr/local/bin
As long as the file sits someplace that is in your path you can open a file by just typing: code
I put that into my
.bash_profile
I tested it and it works.To set it up, launch VS Code. Then open the Command Palette (⇧⌘P) and type shell command to find the Shell Command: Install 'code' command in PATH command.enter image description here
https://code.visualstudio.com/docs/setup/mac