a_girl
a_girl

Reputation: 1205

VSCode error in settings when trying to set Git Bash as default profile for terminal

I tried to set Git Bash as the default terminal in VSCode, but I can't do it successfully. I've tried following the next articles:

  1. How do I use Bash on Windows from the Visual Studio Code integrated terminal?
  2. How to Add Git Bash to VsCode

But they haven't resolved my issue.

I managed to generate profiles in settings.json, but Git Bash doesn't work for some reason unknown to me and VsCode shows an error.

My settings.json:

{
    "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"
        },
        "Git Bash": {
            "source": "Git Bash",
            "path": "C:\\git-sdk-64\\git-bash.exe",
            "args": [
                "--login",
                "-i"
            ]
        },
        "Cygwin": {
            "path": "C:\\cygwin64\\bin\\bash.exe",
            "args": [
                "--login"
            ]
        }
    },
    "terminal.integrated.defaultProfile.windows": "Git Bash"
}

The error:

enter image description here

Does anyone know how to fix this?

My VsCode version:

Version: 1.57.1 (user setup)
Commit: 507ce72a4466fbb27b715c3722558bb15afa9f48
Date: 2021-06-17T13:28:07.755Z
Electron: 12.0.7
Chrome: 89.0.4389.128
Node.js: 14.16.0
V8: 8.9.255.25-electron.0
OS: Windows_NT x64 10.0.19042

Edit:

I use git SDK, which is like git-bash but not exactly. Maybe this is the problem?

Upvotes: 7

Views: 2546

Answers (2)

Dahan Gong
Dahan Gong

Reputation: 182

I just met a same problem. And the solution on my VS Code 1.60.0 is also to rename Git Bash into GitBash.

During debugging using Developer Tools, I found VS Code always "merge" object values with the default values of a same key, so:

  • in VS Code, the Git Bash key has a default value of { source: "Git Bash" }
  • I once wrote {..., "Git Bash": { "path": "D:\\Git\\usr\\bin\\bash.exe", ... }}
  • and then the merged value is {..., "Git Bash": { "source": "Git Bash", "path": "...", ... }}
  • during a function named showProfileQuickPick, VS Code calls _detectProfiles
    • this function sends values of terminal.integrated.profiles.windows and terminal.integrated.defaultProfile.windows to its _primaryOffProcessTerminalService
    • the value of profiles is just the merged one
  • as a result, the object of Git Bash is somehow "illegal" and then ignored

On the contrary, GitBash means to declare a new profile object, so it should work.

Upvotes: 2

timchew2012
timchew2012

Reputation: 61

this finally worked for me

"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": {
            "path": ["C:\\Program Files\\Git\\bin\\bash.exe"],
            "args": [],
            "icon": "terminal-bash"
        }
    },
    "terminal.integrated.defaultProfile.windows": "GitBash"
}

Upvotes: 6

Related Questions