how to open vs code in terminal code example

Example 1: shortcut to open vscode from terminal

path code .

Example 2: install code . path in mac

cat << EOF >> ~/.zshrc
# Add Visual Studio Code (code)
export PATH="/Applications/Visual Studio Code.app/Contents/Resources/app/bin:$PATH"
EOF

Example 3: mac open vs code from terminal

$ alias code="open -a /Applications/Visual\ Studio\ Code.app"

#Open Visual Studio Code by command
$ code .

Example 4: code in terminal

cat << EOF >> ~/.bash_profile
# Add Visual Studio Code (code)
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
EOF

Example 5: adding code . in the terminal

code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}