Add and Open Project Folder in Visual Studio Code using ZSH Terminal? - bash

I am following a series of tutorials to learn command line and, my teacher open and adds the project folder in Atom using the command
atom .
but she is using bash shell, and I am using zsh (is the default shell macOS has since Catalina) and visual studio code.
I've tried the following commands unsuccessfully:
Visual\ Studio\ Code -a
open -a 'Visual Studio Code'
code .
open Visual\ Studio\ Code .
I just want to know what is the equivalent command to her atom . but for vs code in zsh.

The problem was that actually I needed to install the code command to PATH as specified in the official VS Code documentation:
https://code.visualstudio.com/docs/setup/mac
Launch VS Code.
Open the Command Palette (Cmd+Shift+P) and type shell command to find the Shell Command: Install 'code' command in PATH command.
Restart the terminal for the new $PATH value to take effect.
So now you'll be able to type code . in any folder to start editing files in that folder, just like in my atom . example

Related

Adding Visual Studio Code binary to the path in Mac, Command not found, although it is in the $PATH

I want to open Visual Studio Code with the terminal by writing code.
I wrote the following line in the bash_profile
export PATH="/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin:$PATH"
So that the PATH is updated with directory where the binary code is.
Unfortunately, I still get:
tommasos-mbp:~ tommaso$ code
-bash: code: command not found
The weird thing is that the PATH have been correctly updated, indeed if a run in the terminal env, I get:
PATH=/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin:
Also if I run directly in the terminal
/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code
Visual studio code opens perfectly.
What is wrong here?
In case there is new Mac user like me, there is a build-in option in vscode where it will automatically add vscode in the PATH environment variable so that you can access code through Terminal. Follow this Launching vscode from terminal in Mac OS documentation
Lose the double-quotes around your export (the path is escaped, so you don't need them). Otherwise the terminal literally interprets your path as being /Applications/Visual\ Studio ...
export PATH="/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin:$PATH"
Should be:
export PATH=/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin:$PATH

How to run Visual Studio Code from the command line?

I am following the following instructions https://code.visualstudio.com/docs/setup/mac but I have no success. This is what happens when I enter
➜ ~ shell command
I am getting the following:
zsh: command not found: shell
I looked up the following question as well How to open Visual Studio Code from the command line on OSX?, it didn't help.
I have only one terminal option in the VSCode, zsh.
In order to have code open Visual Studio Code from the terminal, you need to add it to the PATH by starting it (from the Launchpad, or Applications), then open its command palette by entering cmd + shift + P. A little text box you can type into will pop up near the top of the window. Type in "shell command" and with the arrow keys you should navigate to the option that says Install 'code' command in PATH and press ENTER.
Now you can cd into a directory and do code . to open VS Code with that directory as the working project directory.
You might need to close and reopen your terminal in order for your shell to use the new alias.
Open Visual Studio
cmd + P(MacOS) or CTRL + P(windows)
will executed a search floating text
type '>shell'(with out the single quotes)
choose/select from the options "Shell Command: Install PATH..."
all set !

Run / Open VSCode from Mac Terminal

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?
According to the docs on Launching from the command line:
Open Visual Studio Code
Open the command pallette with Command + Shift + P (or F1)
Type Shell in command palette
Select Shell Command: Install code in PATH from suggested list
That's it.
Now open your terminal type.
$ code .
To make this change persist after restart on MacOS
Many Mac users find this is forgotten and needs to be re-applied after any restart. This may happen if MacOS has applied the quarantine attribute to VS Code, which the OS uses for the "Are you sure?" notice applied on first using apps downloaded from the internet.
To check if this attribute is applied, look for com.apple.quarantine in the list returned by this command (changing the path if that's not where you installed it):
xattr "/Applications/Visual Studio Code.app"
If that does return com.apple.quarantine, you can remove the attribute using the same command with the -d flag (alongside -r to recursively remove it from all contained files and sudo to allow the change):
sudo xattr -r -d com.apple.quarantine "/Applications/Visual Studio Code.app"
...then do Shell Command : Install code in PATH as above after the attribute has been removed, and it should persist after restart.
Credit: derflounder.wordpress.com article linked to by RicardoVallejo in this comment.
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).
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
Now, you can simply type code . in any folder to start editing files in that folder. [Or code test.txt to go to work on the test.txt file]
To setup path permanently for mac users;
open ~/.zshrc using the below command
vi ~/.zshrc
Add the following path
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
And source it using below command
source ~/.zshrc
Now close the terminal and reopen and run code . command should work properly.
follow some simple steps :
open your visual studio code (vs code).
press F1.
pallete will open in top center with symbol >
type shell .
select intall 'code' command in PATH.
it will be automatically intalled.
Now you can use from terminal by typing
$ code .
Open VSCode, press Command + Shift + P, type Shell in command palette, Select that option => Install code in PATH from suggested list in command palette.
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
which code
and it tells me it put it in /usr/local/bin
Sometimes, just adding the shell command doesn't work. We need to check whether visual studio code is available in "Applications" folder or not. That was the case for me.
The moment you download VS code, it stays in "Downloads" folder and terminal doesn't pick up from there. So, I manually moved my VS code to "Applications" folder to access from Terminal.
Step 1: Download VS code, which will give a zipped folder.
Step 2: Run it, which will give a exe kinda file in downloads folder.
Step 3: Move it to "Applications" folder manually.
Step 4: Open VS code, "Command+Shift+P" and run the shell command.
Step 5: Restart the terminal.
Step 6: Typing "Code ." on terminal should work now.
For macOS 12.0 and above:
Open profile in Notepad
open ~/.zshrc
Create an alias for code, Paste below:
alias code='open -a "Visual Studio Code"' # open file or folder in VSCode e.g. code ~/.zshrc
Now you can open the current folder e.g. code . or any other file/folder by providing its path.
Profit
PS: You can add as many aliases as needed to open a file/folder with different editors. Just mention the editor's name in the alias. For example, open file/folder with sublime text:
alias subl='open -a "Sublime Text"' # open file or folder in sublime e.g. subl ~/.zshrc
And use it like subl .
To set up VS code path permanently on Mac OS;
just open .bash_profile using the following command on terminal
open -t .bash_profile
Then add the following path to .bash_profile
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
save the .bash_profile file and quit the terminal. Then reopen the terminal and type code .to open VS code.
Somehow using Raja's approach worked for me only once, after a reboot, it seems gone.
To make it persistent across Mac OS reboot, I added this line into my ~/.zshrc since I'm using zsh:
export PATH=/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin:$PATH
then
source ~/.zshrc
now, I could just do
code .
even after I reboot my Mac.
For Mac users:
One thing that made the accepted answer not work for me is that I didn't drag the vs code package into the applications folder
So you need to drag it to the applications folder then you run the command inside vs code (shown below) as per the official document
Launch VS Code.
Open the Command Palette (⇧⌘P) and type 'shell command' to find the
Shell Command: Install 'code' command in PATH command.
Yo do this:
Launch Visual Studio Code.
Press Cmd ⌘ + Shift ⇧ + P to open the Command Palette.
Type in shell command and select the Shell command: Install ‘code’ command in PATH to install it.
How about a simple Bash alias that you stick in your .bash_profile ?
alias code="open -a /Applications/Visual\ Studio\ Code.app"
To open the current directory:
code .
I just made a symbolic link from the "code" program supplied in the Visual Studio Code.app bundle to /usr/local/bin (a place where I prefer to put stuff like that and which is already in my path on my machine).
You can make a symbolic link using ln -s like this:
ln -s /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code /usr/local/bin/code
I follow this step it work for me .😁
first open VSC .
open terminal of VSC.
Press cmd+shift+p
uninstall path .
Give permission to it.
Press cmd+shift+p
install path .
then open Mac terminal navigate to root project file
type
code . in root folder It will open VSC . :)
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
add below snipped in your bash profile -
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
I moved VS Code from Downloads folder to Applications, and then i was able to run code in the terminal. I guess, it might help you too.
Open Visual Studio Code
Open the command pallette with Command + Shift + P
Type Shell in command palette
Select Shell Command: Install code in PATH from suggested list
Type code . in mac terminal
I simply created a file called code:
#!/bin/bash
open /Applications/Visual\ Studio\ Code.app $1
Make it executable:
$ chmod 755 code
Then put that in /usr/local/bin
$ sudo mv code /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 prefer to have symlinks in the home directory, in this case at least. Here's how I have things setup:
: cat ~/.bash_profile | grep PATH
# places ~/bin first in PATH
export PATH=~/bin:$PATH
So I symlinked to the VSCode binary like so:
ln -s /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code ~/bin/code
Now I can issue code . in whichever directory I desire.
Since, default shell is zsh in macOS, you can try this:
cat << EOF >> ~/.zshrc
# Add Visual Studio Code (code)
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
EOF
This will add a path to your VS Code, restart your terminal and voila, you're good to go.
code example.py
alias code="/Applications/Visual\ Studio\ Code\ 2.app/Contents/Resources/app/bin/code $1"
the alias to the vs code's bin file with parameters works well
you can do code . after having sourced your bash file
open finder and go to applications and make sure that vscode exists there ,then open type in terminal export PATH="/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
Open VSCode
Go to view --> Command Palette
Search for "shell...install 'code'
Open your terminal and place in the directory you wanna open
Use $ code .
code () {
if [[ $# = 0 ]]
then
open -a "Visual Studio Code"
else
echo "Opening: "$#
"/Applications/Visual Studio Code.app/Contents/MacOS/Electron" $#
fi
}
I put that into my .bash_profile I tested it and it works.

How to open Visual Studio Code from the command line on OSX?

The docs mention an executable called code, but I'm not sure where I can find that so I can put it on my path. The zip I downloaded from the VSCode site did not include any such executable. (I am able to run the .app just fine.)
Is this a Windows-only thing?
From the Visual Studio Code Setup page:
Tip: If you want to run VS Code from the terminal by simply typing 'code', VS Code has a command, Shell Command: Install 'code' command in PATH, to add 'code' to your $PATH variable list.
After installation, launch VS Code. Now open the Command Palette (F1 or ⇧+⌘+P on Mac) and type shell command to find the Shell Command: Install 'code' command in PATH command.
After executing the command, restart the terminal for the new $PATH value to take effect. You'll be able to simply type 'code .' in any folder to start editing files in that folder.
⚡️ The Easy Solution.
Download, install and open Visual Studio Code.
Open the Command Palette (⌘ + ⇧ + P on Mac) OR View ❯ Command Palette
🌟 3. Type shell command to find
Shell Command: Install 'code' command in PATH command
Install it and you're done
📟 Here's a complimentary GIF.
After that, you can use code or code . in the terminal.
code
Peace! ✌️
If you'd like to go a little bit further and learn a couple of great tips/tricks for using the VSCode CLI, I made a YouTube video on my workflows.
If you want to open a file or folder on Visual Studio Code from your terminal, iTerm, etc below are the commands which come as default when you install Visual Studio Code
To open Visual Studio Code from command line
code --
To open the entire folder/directory
code .
To open a specific file
code file_name
eg:- code index.html
We since updated the script to the following syntax to support multiple files and folders as arguments and to fix an issue with not detecting the current working directory properly:
code () {
VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
}
Update for our VS Code 1.0 release:
Please use the command Install 'Code' command in path or Install 'code-insiders' command in path from the command palette (View | Command Palette) to make Code available to the command line.
For me on Macbook Book Pro 2019 MacOS version 10.15.6, shortcut to open command palette in VSCode was Shift + Command + P.
On opening it one has to just write install code and press enter.
After that just open the terminal and type code your vscode will start opening.
This was the tutorial I was looking for in this thread. It shows the way to open files in Visual Studio Code by writing code .
1.- Open the file
Bash
open ~/.bash_profile
Terminal OS
open ~/.zshrc
2.- Add in your file the :
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
3.- Reinicialize terminal and try in the folder you want to open
code .
4.- Then you can use it as shown in this comment: https://stackoverflow.com/a/41821250/10033560
I have a ~/bin/code shell script that matches the command #BengaminPasero wrote.
#!/bin/bash
VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
I prefix ~/bin: to my $PATH which allows me to add a bunch of one off scripts without polluting my ~/.bash_profile script.
Note: Only for Windows Users.
As many folks already suggested ways to open code from command prompt using code . command. This will only open Visual Studio Code Stable build. But If you have downloaded Visual Studio Code Insider build/version (Which has all latest build/features but unstable version) then you need to follow below instructions in windows :
Go to Control Panel\System and Security\System. Click on Advanced System Settings
Click on Environment Variables
Under System Variables tab, Click on Edit for Path Variable
Add a new path C:\Users\tsabu\AppData\Local\Programs\Microsoft VS Code Insiders\bin
(or)
C:\Program Files\Microsoft VS Code Insiders\bin based on location at which you have installed vscode insider in your machine.
Open a new command prompt and type code-insiders . to open vscode-insider
build/version
After opening VSC and pressing (Command + Up + P) I tried typing in "shell command" and nothing came up. In order to get "Shell Command: Install 'code' command in PATH command" to come up, you must do the following:
Press (Command, Up, P)
Type > (this will show and run commands)
Then type Shell Command: Install 'code' command in PATH command. It should then come up.
Once you click it, it will update and you should be good to go!
MacOS X Launch from Command Line docs
On OSX Mavericks I created a bash script named vscode (adapted from the .bashrc in VSCode Setup) in ~/bin:
#!/bin/bash
if [[ $# = 0 ]]
then
open -a "Visual Studio Code"
else
[[ $1 = /* ]] && F="$1" || F="$PWD/${1#./}"
open -a "Visual Studio Code" --args "$F"
fi
vscode <file or directory> now works as expected.
If you are using VS Code Insiders:
code-insiders .
If you are using VS Code:
code .
If you install Your vs code in Download folder you need to move the VS code to Application folder then open the vs code ,then press shift + command + p after you will see the below image. Then you need to type code . Now you are good to go.
Try this one
Open Visual Studio Code and press Command + Shift + P then type Shell in command palette now you are able to find this option like Shell Command : Install code in PATH from suggested list in command palette. Select that options.
Open VSCode via Terminal/Command Prompt
That's it.
Now open your terminal type.
$ code .
Steps to run code . command in mac to start the VSCode app -
Open VSCode
Open command pallet(Cmd+Shift+P)
Enter Shell Command: Install 'code' command in PATH and select
You will get the notification saying Shell command 'code' successfully installed in PATH.
Restart the terminal and enter code .
This will open VSCode from the current folder files in it.
You can use the vscode: protocol that Visual Studio Code defines:
open vscode://file/full/path/to/project/or/file
You can also use
/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code
if you do not fancy modifying your path
I discovered a neat workaround for mingw32 (i.e. for those of you using the version of bash which is installed by git-scm.com on windows):
code () { VSCODE_CWD="$PWD" cmd //c code $* ;}
its very simple:
Launching from the Command Line
You can also run VS Code from the terminal by typing 'code' after adding it to the path:
Launch VS Code.
Open the Command Palette (⇧⌘P) and type 'shell command' to find the Shell Command: Install 'code' command in PATH command.
source
https://code.visualstudio.com/docs/setup/mac
I ran: open -a "Visual Studio Code" [folder-name] to open a folder with my Visual Studio Code application. Folder name is optional if you just want to open the application. Not sure if this is exactly your use-case, but hope this helps!
This is what worked for me on Mac OS Catalina -- found here (thanks, Josiah!)
If you're on Mac OS Catalina, you need to edit your .zprofile instead of .bash_profile.
Edit your ~/.zprofile file: vim ~/.zprofile
Add the following code in it, on it's own line: code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
Save the file: :wq
Re-run the updated file: source ~/.zprofile.
Test that running code . opens your current folder in VS Code!
In my case I had to use an alias:
alias code="/<PATH TO VSCODE>/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code"
You can add this alias in your ~/.bash_profile.
I added this to my ~/.profile
alias vscode='/Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron'
then
. ~/.profile
afterwards I can just do
vscode
from the terminal
Added this to /usr/local/bin/code, you might have to modify the path if they are different.
#!/usr/bin/env bash
CONTENTS="/Applications/Visual Studio Code.app/Contents"
ELECTRON="$CONTENTS/MacOS/Electron"
CLI="$CONTENTS/Resources/app/out/cli.js"
ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$#"
exit $?
Make executable afterwards
sudo chmod +x /usr/local/bin/code
I had this issue because of VS Code Insiders.
The path variable was there but I needed to rename the code-insiders.cmd inside to code.cmd .
Maybe this is useful to someone.
For windows Users
just type in
>code .
More commands here
https://code.visualstudio.com/docs/editor/command-line
If you're using visual code insiders and you want to open a file or folder in Visual Studio Code insiders from your terminal or any other command line tool then you can refer to the commands below which come by default inside visual studio code insider.
To open Visual Studio Code from command line
code-insiders --
To open the entire folder/directory
code-insiders .
To open a specific file
code-insiders file_name
eg:- code index.html
VSCode now supports it out of the box with version 1.58. Just type:
$ cd path/to/your/directory
$ code .
The instruction given at VS Code Command Line for launching a path are incorrect; the leading colon shown in the example doesn't work. However, launching with a backslash terminated directory name opens the specified directory as expected.
So, for example,
code C:\Users\DAVE\Documents\Programming\Angular\StringCalculator\src\
opens the Visual Studio Code editor in directory C:\Users\DAVE\Documents\Programming\Angular\StringCalculator\src.
Important: The terminal backslash, though optional, is useful, as it makes clear that the intend is to open a directory, as opposed to a file. Bear in mind that file name extensions are, and always have been, optional.
Beware: The directory that gets appended to the PATH list is the \bin directory, and the shell command code launches a Windows NT Command script.
Hence, when incorporated into another shell script, code must be called or started if you expect the remainder of the script to run. Thankfully, I discovered this before my first test of a new shell script that I am creating to start an Angular 2 project in a local Web server, my default Web browser, and Visual Studio Code, all at once.
Following is my Angular startup script, adapted to eliminate a dependency on one of my system utilities that is published elsewhere, but not strictly required.
#echo off
goto SKIPREM
=========================================================================
Name: StartAngularApp.CMD
Synopsis: Start the Angular 2 application installed in a specified
directory.
Arguments: %1 = OPTIONAL: Name of directory in which to application
is installed
Remarks: If no argument is specified, the application must be in
the current working directory.
This is a completely generalized Windows NT command
script (shell script) that uses the NPM Angular CLI to
load an Angular 2 application into a Node development
Web server, the default Web browser, and the Visual
Studio Code text editor.
Dependencies: Unless otherwise specified in the command line, the
application is created in the current working directory.
All of the following shell scripts and programs must be
installed in a directory that is on the Windows PATH
directory list.
1) ShowTime.CMD
2) WWPause.exe
3) WWSleep.exe
4) npm (the Node Package Manager) and its startup
script, npm.cmd, must be accessible via the Windows
PATH environment string. By default, this goes into
directory C:\Program Files\nodejs.
5) The Angular 2 startup script, ng.cmd, and the Node
Modules library must be installed for global access.
By default, these go into directory %AppData%\npm.
Author: David A. Gray
Created: Monday, 23 April 2017
-----------------------------------------------------------------------
Revision History
-----------------------------------------------------------------------
Date By Synopsis
---------- --- --------------------------------------------------------
2017/04/23 DAG Script created, tested, and deployed.
=======================================================================
:SKIPREM
echo BOJ %~0, version %~t0
echo.
echo -------------------------------------------------------
echo Displaying the current node.js version:
echo -------------------------------------------------------
echo.
node -v
echo.
echo -------------------------------------------------------
echo Displaying the current Node Package Manager version:
echo -------------------------------------------------------
echo.
call npm -v
echo.
echo -------------------------------------------------------
echo Loading Angular starter application %1
echo into a local Web server, the default Web browser, and
echo the Visual Studio Code text editor.
echo -------------------------------------------------------
echo.
if "%1" neq "" (
echo.
echo -------------------------------------------------------
echo Starting the Angular application in directory %1
echo -------------------------------------------------------
echo.
cd "%~1"
call code %1\src\
) else (
echo.
echo -------------------------------------------------------
echo Starting the Angular application in directory %CD%
echo -------------------------------------------------------
echo.
call code %CD%\src\
)
call ng serve --open
echo.
echo -------------------------------------------------------
echo %~nx0 Done!
echo -------------------------------------------------------
echo.
Pause
$> open -a "Visual Studio Code" [file-name]
link your currentily folders to vscode.
Windows Registry Editor Version 5.00
; Directory\Background\shell => on empty space
[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode]
"Icon"="C:\\current-folder-vscode\\Code.exe,0"
#="VsCode"
[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode\command]
#="C:\\current-folder-vscode\\Code.exe ."
; Directory\shell => on a folder
[HKEY_CLASSES_ROOT\Directory\shell\vscode]
#="VsCode"
"Icon"="C:\\current-folder-vscode\\Code.exe,0"
[HKEY_CLASSES_ROOT\Directory\shell\vscode\command]
#="C:\\current-folder-vscode\\Code.exe ."
If you install VS CODE using snap. You will need to add /snap/bin in your PATH environment variable.
so - open your .bashrc or .zshrc
and add /snap/bin in your PATH environment variable
reload terminal,
and than code comand will start it

How do I set up a link to open up Visual Studio Code from terminal on OSX?

I've recently installed Visual Studio Code and I love it! In the past, I've used sublime text 2/3 and at some point I copied code to allow subl . command to open the current directory with sublime.
Question:
How can I write a similar code to allow visual studio code to open up the current directory like I've done in the past with sublime.
Where should I put paste this code?
Desired alias/link/command would be code .
Does the command on this video
From version 1.0 use the command Install 'Code' command in path from the command palette (View | Command Palette) to make Code available to the command line.
Historical answer:
With VSCode 0.3.0 the startup script should now be configured to be this:
code () {
VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
}
UPDATE:
If this doesnt work for you uninstall VSC and reinstall it; for this will only work with 0.3.0+
Visual Code has a self-service means to do the same!
Followed https://code.visualstudio.com/docs/setup/mac#_installation
Update
As pointed out in comments by Tony, Atom Shell has been renamed to Electron.
My updated code should read:
code() { (/Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron "$1" &) }
Also, I recommend using official way, as described in Benjamin's answer:
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*; }
You should create a command to start the editor in ~/.bash_profile file. This file is read each time you open terminal and start your bash session.
As the process should be started in the background and we want to pass a directory or a file as an argument I would add such single line function to .bash profile:
code() { (/Applications/Visual\ Studio\ Code.app/Contents/MacOS/Atom "$1" &) }
Where /Applications/Visual\ Studio\ Code.app is a path to your Visual Studio Code app. You may need to adjust it if you installed it somewhere else.
This function opens Atom editor that is a base of Visual Studio Code and passes the first parameter to it with $1 expansion. Ampersand & will make the process detach from terminal and run in the background. The whole function body is put in brackets () to quiet messages about detaching and ending the process.
If the .bash_profile file is missing on your system you will have to create it first.
After editing the file you will have to restart your current bash session.
I set it up following the docs here: https://code.visualstudio.com/Docs/setup and added a code definition to my .bash_profile.
UPDATE (6/10/2015): This answer originally contained the code from the linked site. I have now removed the code from this answer as the linked site now recommends a different code implementation. (as Benjamin pointed out in the comments). Please see the link for the recommended code to add to your .bash_profile.

Resources