Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitBash not showing up as a terminal option in Visual Studio Code

I am trying to insert GitBash as an option in Visual Studio Code. My settings look like so:

"terminal.integrated.profiles.windows": {
    "PowerShell": {
      "source": "PowerShell",
      "icon": "terminal-powershell"
    },
    "Command Prompt": {
      "path": [
        "${env:windir}\\Sysnative\\cmd.exe",
        "${env:windir}\\System32\\cmd.exe"
      ],
      "args": [],
      "icon": "terminal-cmd"
    },
    "GitBash": {
      "source": "GitBash",
      "path": ["F:\\Code\\Git\\bin\\bash.exe"],
      "icon": "terminal-bash"
    }
  },
  "terminal.integrated.defaultProfile.windows": "GitBash"

However, at the last line, the error that Visual Studio Code gave is:

Value is not accepted. Valid values: "PowerShell", "Command Prompt".(1)
The default profile used on Windows. This setting will currently be ignored if either #terminal.integrated.shell.windows# or #terminal.integrated.shellArgs.windows# are set.

I do not understand where I went wrong.

Note: "terminal.integrated.shell.windows" is deprecated as of April 2021.

like image 314
Lucian Anghel Avatar asked Jun 21 '21 12:06

Lucian Anghel


People also ask

Why is VScode not showing terminal?

Changing Default Command Line Shell Then, click on the arrow on the side of a plus (+). Here, choose Select Default Profile. Then, select any other type of command line shell. Then, restart vs code and try working on terminal.

How do I set git bash as default terminal in VScode?

Another way to select a default terminal is to open up a new terminal in VS Code. Next to the big plus sign, click on the dropdown and select “Select Default Profile“. From the dropdown select “Git Bash” and you're all set. Reopen a new terminal to make sure Git Bash opens up as default.

How do I enable terminal code in Visual Studio?

To open the terminal: Use the Ctrl+` keyboard shortcut with the backtick character. Use the View > Terminal menu command. From the Command Palette (Ctrl+Shift+P), use the View: Toggle Terminal command.

Why can't I open Git Bash in Visual Studio Code?

Delete the source property, and see if the issue resolves and you can open a git bash terminal in Visual Studio Code. Also, you may need to restart Visual Studio Code after making these changes. It might be a separate bug, but the terminal.integrated.profiles.windows setting won't detect any new profiles added until you restart.

Can I use Git Bash as the built-in terminal in VS Code?

Many clients will require me to work on a Windows laptop for access to their networks. Fortunately, I can change the settings within VS Code to use Git Bash as the built-in terminal.

How to integrate gitbash with Visual Studio Code?

Now dwelling further to the integration of GitBash with VSCode we need to follow sequential steps in order to integrate Git Bash with Visual Studio Code which is as follows: Add the properties to the setting page. Step 1: Open Terminal in VScode by using the shortcut key Ctrl+~.

How to add Bash to VSCode terminal?

Step 1: Open Terminal in VScode by using the shortcut key Ctrl+~. Here you will see that currently, it has PowerShell and we have to add bash to it. Step 2: Then, you have to open settings by File->Preferences->Settings or by pressing Ctrl+, . You have to click on the Open Settings (JSON) icon as shown in the image below:


4 Answers

VS Code version 1.57.1.

Added path of Git, Git\bin, Git\cmd in env. Had "Git Bash" profile with source and path elements. Removed source and kept only the path. When adding defaultProfile as "Git Bash" got "Value is not accepted" error. Restarting VS Code did not help.

Changing "Git Bash" to "GitBash" (space removed) finally worked for me:

"terminal.integrated.profiles.windows": {
    "GitBash": {
      "path": ["D:\\ProgramFiles\\Git\\bin\\bash.exe"],
      "args": []
    },
    ...
}
"terminal.integrated.defaultProfile.windows": "GitBash"

I am not sure if space is actually the problem. Because there is a profile "Command Prompt" with space in its name and recognized!!! To confirm this further, changed "PowerShell" to "Power Shell", and it worked too.

I am not clear how space matters only in the "GitBash" profile.

like image 124
nagu Avatar answered Oct 21 '22 20:10

nagu


I believe Visual Studio Code uses your PATH variables to find which profiles are available on your machine. I am guessing you do not have the location of Git Bash set in your PATH. But, that should be fine since you specify the path property in the setting. The issue is you are also setting the source property. According to the description for the terminal.integrated.profiles.windows setting, you can either set the source or the path, not both:

The Windows profiles to present when creating a new terminal via the terminal dropdown. Set to null to exclude them, use the source property to use the default detected configuration. Or, set the path and optional args

Delete the source property, and see if the issue resolves and you can open a git bash terminal in Visual Studio Code.

Also, you may need to restart Visual Studio Code after making these changes. It might be a separate bug, but the terminal.integrated.profiles.windows setting won't detect any new profiles added until you restart.

like image 27
Timothy G. Avatar answered Oct 21 '22 22:10

Timothy G.


For anybody using a custom dir for git installation: It does not work with Version: 1.60.2 (user setup)

Win10 User:

  1. Install or just copy git in C:\Program Files
  2. Add Path Variables name: GIT_HOME_2 variable: C:\Program Files\Git
  3. In double click on Path and add "%GIT_HOME_2%\bin"
  4. Open VS Code, you should now see the bash terminal
{
    "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
       
    },
    "terminal.integrated.env.windows": {
    
    },
    "terminal.integrated.defaultProfile.windows": "Git Bash"
}
like image 5
Jotaro Avatar answered Oct 21 '22 20:10

Jotaro


I have VS Code 1.63.2

Removing the source property or the space in "Git Bash" didn't help. But I found this on their official site and I noticed that the .exe file itself is specified in path:

{
  "terminal.integrated.profiles.windows": {
    "My PowerShell": {
      "path": "pwsh.exe",
      "args": ["-noexit", "-file", "${env:APPDATA}PowerShellmy-init-script.ps1"]
    }
  },
  "terminal.integrated.defaultProfile.windows": "My PowerShell"
}

So I tried adding \\bash.exe to the path in the settings and it worked:

"terminal.integrated.profiles.windows": {
  "GitBash": {
    "path": "D:\\Git\\bin\\bash.exe",
    "icon": "terminal-bash"
  }
},
"terminal.integrated.defaultProfile.windows": "GitBash"
like image 3
trtskvalerie Avatar answered Oct 21 '22 21:10

trtskvalerie