Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you open a directory/entire folder in Visual Studio Code using command line?

Tags:

git-bash

Is there a way to open a folder/directory from git bash/shell emulator? I know you can use 'start' then the file name to open one file, but is there a way to open the entire folder?

Edit: If you're trying to open an entire folder with Visual Studio Code (which is what I was trying to do), follow these steps:

  1. Navigate inside the folder in git bash.
  2. Then run the command: code . --new-window
  3. Your project with all files in that folder should open in a new Visual Studio Code window.
like image 762
Stephanie McNaught Avatar asked Nov 01 '17 22:11

Stephanie McNaught


2 Answers

Haven't used "Git Bash"... I assume it is a bash shell emulator. If so, try:

cd <folder>

cd stands for Change Directory.

To open the current folder, try:

start .

The '.' is the current folder. To open in VS Code try:

code .

code CLI needs to be installed. More info on use here.

like image 174
Robert Brisita Avatar answered Oct 19 '22 11:10

Robert Brisita


I use this alias in my ~/.bashrc to mirror the open functionality I miss from OSX:

function open() {
    # if argument != '.', open full-path to argument
    [ "$@" = '.' ] && dir_path="." || dir_path=$(realpath "$@")
    start $dir_path
}

You can use it to open relative paths to directories: open /relativeDirectory

Here's the same code in an easier to read manner:

function open() {
    arg="$@"
    dir_path=$(realpath $arg)
    if [ "$arg" = '.' ]; then
      dir_path="."
    fi
    start $dir_path
}
like image 1
Jared Wilber Avatar answered Oct 19 '22 13:10

Jared Wilber