Change Shell In Visual Studio Code Integrated Terminal

 
Facebooktwittergoogle_pluslinkedinFacebooktwittergoogle_pluslinkedin

There is a lot of widespread confusion among many Visual Studio Code users around how to switch between different Command Shells from within the Visual Studio Code Integrated Terminal (which you can launch using the shortcut: CTRL + `). The Intent of this post is to demonstrate different possible ways to switch/change between the various Command Shells that are available on your local Windows 10 machine, within the Visual Studio Code Integrated Terminal.

Visual Studio Code Installed in a Windows 10 machine uses Windows PowerShell as the default Shell in the Integrated Terminal within the IDE. However, you may need to switch from Windows PowerShell to another Shell within the VS Code Integrated Terminal, depending upon your specific context and requirement. We will explore switching from native Windows PowerShell to other common Shells like the following:

  • Git Bash
  • Windows Subsystem For Linux (WSL) Bash
  • Windows Command Shell (CMD)
  • PowerShell Core

Let’s see how we can change the VS Code integrated Terminal Shell to either/each of the above mentioned options.

Git Bash Shell In Visual Studio Code Integrated Terminal

For switching to and using Git Bash as your current shell in VS Code Integrated Terminal, you need to first have Git for Windows Installed on your Windows 10 machine.

If Git for Windows is not already installed on your machine, you can download from here and Install: Git For Windows x64 Installer. Installing Git for Windows would also install Git Bash on your machine

Once Git (and Git Bash) is Installed on your machine, you can then choose Git Bash as your current shell within the VS Code Integrated Terminal by following either of the below 3 ways:

  • Type “C:\Program Files\Git\bin\bash.exe” (including the quotes) on the prompt of whatever Shell you are currently on within the VS Code Integrated Terminal (like if you are currently in PowerShell Core, or Windows PowerShell, or Git Bash, or CMD). Doing so will open the Git Bash Immediately within the same Integrated Terminal Window. You can see the same in the screenshot given below, where I typed “C:\Program Files\Git\bin\bash.exe” on the PowerShell prompt within the VS Code Integrated Terminal, and I was Immediately taken to the Git Bash shell.

Switching to GHit Bash from Windows Command Prompt in Visual Studio Code

  • Press CTRL + SHIFT + P within VS Code to open up the Command Palette visible on the top of the editor. Type “Default Shell” in the command palette, and you will see an option “Terminal : Select Default Shell“. Selecting this option will show you a drop-down list of all terminal shells currently available on your machine, and from where you can choose the Shell of your choice – In this case, you would choose the item Git Bash C:\Program Files\Git\bin\bash.exe. However, you will not see an Immediate change in the Shell being used in the current Terminal Instance you are on. You will need to manually create a new Terminal Instance by clicking the plus icon on the top-right of the TERMINAL panel. This action creates a new Terminal Instance (and adds another entry in the drop-down list showing all existing Terminal Instances), which will be using the new shell you just switched to.

Selecting Git Bash From Visual Studio Code Command Palette

  • Inside the settings.json file of VS Code, you would need to find and set a particular key "terminal.integrated.shell.windows" for configuring Git Bash as the default VS Code Integrated Terminal Shell. The final key:value pair should like this on Windows 10: "terminal.integrated.shell.windows": "C:\\WINDOWS\\Git\\bin\\bash.exe". Doing this would ensure that going forward, Git Bash will be your default shell for the VS Code Integrated Terminal unless you change the same again.

Windows Subsystem For Linux (WSL) Bash Shell In Visual Studio Code Integrated Terminal

For using Windows Subsystem For Linux (WSL) Bash as your current shell in VS Code Integrated Terminal , you need to first have WSL enabled on your Windows 10 machine.

WSL is an optional Windows feature provided from Windows 10 Anniversary Update onward. Hence, if your current OS Build version of Windows 10 is >=1607, you can enable the WSL feature in either of the 2 ways given below:

  • Through the GUI: Control Panel” -> “Programs & Features” -> “Turn Windows Features On or Off” -> Select Windows Subsystem For Linux -> Restart the machine
  • Through PowerShell: Open PowerShell as Administrator on your machine, and run the following PowerShell command to enable WSL on Windows 10

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Once WSL is enabled on your machine, you can then choose WSL Bash as your current shell within the VS Code Integrated Terminal by following either of the below 3 ways:

  • Type “wsl” (without the quotes) on the prompt of whatever Shell you are currently on within the VS Code Integrated Terminal (like if you are currently in PowerShell Core, or Windows PowerShell, or Git Bash, or CMD). Doing so will open the WSL Bash Immediately within the same Integrated Terminal Window. You can see the same in the screenshot given below, where I typed wsl on the Git Bash Shell prompt within the VS Code Integrated Terminal, and I was Immediately taken to the WSL Bash shell.

Switching to WSL Bash from Git Bash in Visual Studio Code

  • Press CTRL + SHIFT + P within VS Code to open up the Command Palette visible on the top of the editor. Type “Default Shell” in the command palette, and you will see an option “Terminal : Select Default Shell“. Selecting this option will show you a drop-down list of all terminal shells currently available on your machine, and from where you can choose the Shell of your choice – In this case, you would choose the item WSL Bash C:\WINDOWS\System32\wsl.exe. However, you will not see an Immediate change in the Shell being used in the current Terminal Instance you are on. You will need to manually create a new Terminal Instance by clicking the plus icon on the top-right of the TERMINAL panel. This action creates a new Terminal Instance (and adds another entry in the drop-down list showing all existing Terminal Instances), which will be using the new shell you just switched to.

Selecting WSL Bash From Visual Studio Code Command Palette

  • Inside the settings.json file of VS Code, you would need to find and set a particular key "terminal.integrated.shell.windows" for configuring WSL Bash as the default terminal shell. The final key:value pair should like this on Windows 10: "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe". Doing this would ensure that going forward, WSL Bash will be your default shell for the VS Code Integrated Terminal unless you change the same again.

Windows Command Prompt (CMD) Shell In Visual Studio Code Integrated Terminal

For using Windows Command prompt (CMD) as your shell, you will need to

  • Type “cmd.exe” (without the quotes) on the prompt of whatever Shell you are currently on within the VS Code Integrated Terminal (like if you are currently in PowerShell Core, or Windows PowerShell, or Git Bash, or WSL Bash). Doing so will open the Windows Command Prompt Immediately within the same Integrated Terminal Window. You can see the same in the screenshot given below, where I typed “cmd.exe” on the WSL prompt within the VS Code Integrated Terminal, and I was Immediately taken to the Windows Command Prompt.

Switchin Shell From WSL to Windows Command Prompt In Visual Studio Code

  • Press CTRL + SHIFT + P within VS Code to open up the Command Palette visible on the top of the editor. Type “Default Shell” in the command palette, and you will see an option “Terminal : Select Default Shell“. Selecting this option will show you a drop-down list of all terminal shells currently available on your machine, and from where you can choose the Shell of your choice – In this case, you would choose the item Command Prompt C:\Windows\System32\cmd.exe. However, you will not see an Immediate change in the Shell being used in the current Terminal Instance you are on. You will need to manually create a new Terminal Instance by clicking the plus icon on the top-right of the TERMINAL panel. This action creates a new Terminal Instance (and adds another entry in the drop-down list showing all existing Terminal Instances), which will be using the new shell you just switched to.

Select Windows Command Prompt From Visual Studio Code Command Palette

  • Inside the settings.json file of VS Code, you would need to find and set a particular key "terminal.integrated.shell.windows" for configuring Windows Command Prompt as the default terminal shell. The final key:value pair should like this on Windows 10: "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe". Doing this would ensure that going forward, Windows Command Prompt will be your default shell for the VS Code Integrated Terminal unless you change the same again.

PowerShell Core Shell In Visual Studio Code Integrated Terminal

For using PowerShell Core as your current shell in the VS Code Integrated Terminal, you need to first have PowerShell Core for Windows Installed on your Windows 10 machine. PowerShell Core can very well co-exist with Windows PowerShell on the same Windows machine, without any conflicts. You can Install PowerShell Core after downloading the same from here: PowerShell Core x64 Installer @ Github

  • Type “pwsh.exe” (without the quotes) on the prompt of whatever Shell you are currently on within the VS Code Integrated Terminal (like if you are currently in Windows PowerShell, or Git Bash, or WSL Bash, or CMD). Doing so will open the PowerShell Core Prompt Immediately within the same Integrated Terminal Window. You can see the same in the screenshot given below, where I typed “pwsh.exe” on the WSL prompt within the VS Code Integrated Terminal, and I was Immediately taken to the PowerShell Core Prompt.

Switching to PowerShell Core from WSL in Visual Studio Code

  • Inside the settings.json file of VS Code, you would need to find and set a particular key "terminal.integrated.shell.windows" for configuring PowerShell Core Prompt as the default terminal shell. The final key:value pair should like this on Windows 10: "terminal.integrated.shell.windows": "C:\\program Files\\PowerShell\\6\\pwsh.exe". Doing this would ensure that going forward, PowerShell Core Prompt will be your default shell for the VS Code Integrated Terminal unless you change the same again.
  • NOTE: As of the current VS Code version (1.33.0), you would not be able to switch to PowerShell Core as your current shell using the VS Code Command Palette. This is so because VS Code does not yet detect PowerShell Core Installed on your local Windows machine as a valid Shell environment. It would only show Windows PowerShell in the available Shells drop-down list, alongside CMD and any other Shells available on your local Windows machine.

That’s it for now folks. Hope you found this post useful, and now have a better Idea now on how to switch between different Command Shells within your Visual Studio Code Integrated terminal. For any queries/suggestions/observations/opinions, please feel free to comment in the Comments section below. I will respond back to you at the earliest I can.

Facebooktwittergoogle_pluslinkedinFacebooktwittergoogle_pluslinkedin

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.