Open vs code through terminal using code command in Mac OS

Edit the ~/.bash_profile file

code () {
    if [[ $# = 0 ]]
    then
        open -a "Visual Studio Code"
    else
        [[ $1 = /* ]] && F="$1" || F="$PWD/${1#./}"
        open -a "Visual Studio Code" --args "$F"
    fi
}

Reproduced in: https://my.oschina.net/u/3117745/blog/1516678


Read More: