GitBash未在VisualStudioCode中显示为终端选项

我试图在 Visual Studio Code 中插入 GitBash 作为一个选项。我的设置如下所示:

"terminal.integrated.profiles.windows": {
    "PowerShell": {
      "source": "PowerShell",
      "icon": "terminal-powershell"
    },
    "Command Prompt": {
      "path": [
        "${env:windir}Sysnativecmd.exe",
        "${env:windir}System32cmd.exe"
      ],
      "args": [],
      "icon": "terminal-cmd"
    },
    "GitBash": {
      "source": "GitBash",
      "path": ["F:CodeGitbinbash.exe"],
      "icon": "terminal-bash"
    }
  },
  "terminal.integrated.defaultProfile.windows": "GitBash"

但是,在最后一行,Visual Studio Code 给出的错误是:

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.

我不明白我哪里出错了。

注意:"terminal.integrated.shell.windows"自 2021 年 4 月起已弃用。

回答

我相信 Visual Studio Code 使用您的 PATH 变量来查找您的机器上可用的配置文件。我猜你没有在你的 PATH 中设置 Git Bash 的位置。但是,这应该没问题,因为您path在设置中指定了属性。问题是您也在设置该source属性。根据该说明terminal.integrated.profiles.windows的设置,您可以设置source path,而不是两个:

通过终端下拉菜单创建新终端时要显示的 Windows 配置文件。设置为 null 以排除它们,使用该source属性使用默认检测到的配置。或者,设置path和可选args

删除该source属性,看看问题是否解决,您可以在 Visual Studio Code 中打开一个 git bash 终端。

此外,您可能需要在进行这些更改后重新启动 Visual Studio Code。这可能是一个单独的错误,但在terminal.integrated.profiles.windows您重新启动之前,该设置不会检测到任何添加的新配置文件。

  • Added path of Git, Gitbin, Gitcmd in env. Removed source and mentioned only the path. Restarted VS Code. No change in behavior. "Git Bash" profile is not recognized.
  • Still the same error. Thanks tho

回答

VS 代码版本 1.57.1​​。

在 env 中添加 Git、Gitbin、Gitcmd 的路径。具有带有源和路径元素的“Git Bash”配置文件。删除了源并只保留了路径。将 defaultProfile 添加为“Git Bash”时出现“不接受值”错误。重新启动 VS Code 没有帮助。

将“Git Bash”更改为“GitBash”(删除了空格)终于对我有用了:

"terminal.integrated.profiles.windows": {
    "GitBash": {
      "path": ["D:ProgramFilesGitbinbash.exe"],
      "args": []
    },
    ...
}
"terminal.integrated.defaultProfile.windows": "GitBash"

我不确定空间是否真的是问题所在。因为有一个配置文件“命令提示符”在其名称中带有空格并被识别!!!为了进一步确认这一点,将“PowerShell”更改为“Power Shell”,它也有效。

我不清楚空间仅在“GitBash”配置文件中的重要性。


以上是GitBash未在VisualStudioCode中显示为终端选项的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>