Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Bash on Windows from the Visual Studio Code integrated terminal?

Visual Studio Code on Windows uses PowerShell by default as the integrated terminal. If you want to use Bash from Visual Studio Code, what steps should be followed?

like image 671
Mahade Walid Avatar asked Mar 05 '17 09:03

Mahade Walid


People also ask

Does VS code support bash?

VS Code provides excellent extensions for Bash scripting.


4 Answers

  1. Install Git from https://git-scm.com/download/win

  2. Open Visual Studio Code and press and hold Ctrl + ` to open the terminal.

    Enter image description here

  3. Open the command palette using Ctrl + Shift + P.

  4. Type - Select Default Profile

  5. Select Git Bash from the options

  6. Click on the + icon in the terminal window

  7. The new terminal now will be a Git Bash terminal. Give it a few seconds to load Git Bash

    Enter image description here

  8. You can now toggle between the different terminals as well from the dropdown in terminal.

    Enter image description here

like image 55
Himanshu Avatar answered Oct 17 '22 12:10

Himanshu



You no longer need to type in bash.exe path manually. This answer is deprecated. Now you can switch to bash directly, if you have git installed in the default path. If you installed git to a different path you need to use the below solution.


Install Git from https://git-scm.com/download/win.

Then open Visual Studio Code and open the command palette using Ctrl + Shift + P. Then type "open user setting", and then select "Open User Settings" from the drop down menu.

Visual Studio Code command palate

Then this tab will open up with default settings on left and your settings on the right:

enter image description here

Now copy this line of code to your own settings page (the pane on the right hand side) and save - "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"

Note: "C:\\Program Files\Git\bin\bash.exe" is the path where the bash.exe file is located from the Git installation. If you are using the Windows Subsystem for Linux (WSL) Bash shell, the path would be "C:\Windows\System32\bash.exe"

Now press Ctrl + ` to open up the terminal from Visual Studio Code. And you will have Bash -

Enter image description here

like image 38
Mahade Walid Avatar answered Oct 17 '22 12:10

Mahade Walid


Updated: Newer versions of Visual Studio Code have the Select Default Shell command in the terminal pull down menu:

Select Default Shell option

Remember that it just lists the shells that are in your %PATH% environment variable. For shells that aren't in your path, see other answers.

Extra tip: when you start bash it will just execute .bashrc, if you have initialization commands in .bash_profile you must copy it to .bashrc. It's essential for using Conda enviroments in Git Bash.

Before version 1.36 (June 2019)

The easiest way now (at least from Visual Studio Code 1.22 on) is to type Shift + Ctrl + P to open the Command Palette and type:

Select Default Shell

Now you can easily select your preferred shell between the ones found in your path:

Shell selection list

For shells that aren't in your %PATH%, see the other answers.

See the complete Visual Studio Code shell reference. There's lot of meaty stuff.

like image 104
neves Avatar answered Oct 17 '22 12:10

neves


Press and hold Ctrl + ` to open the terminal. Inside the terminal, type bash to use Git Bash in the terminal. Note: Make sure you have Git Bash installed on your machine.

If you wish to use PowerShell again, just type powershell in the terminal. To use the Windows command line, type cmd in the terminal.

The setting you choose will be used as your default.

like image 48
Isaac Sekamatte Avatar answered Oct 17 '22 11:10

Isaac Sekamatte