Windows上的Visual Studio Code默认使用PowerShell作为集成终端。如果你想从Visual Studio Code中使用Bash,应该遵循哪些步骤?


当前回答

(2021, VSC v.1.55.1)

如何添加Git Bash为默认终端,对于那些安装他们的Git Bash不是在默认路径:

在Visual Studio Code中使用Ctrl +打开设置, a)在“搜索设置”(截图中红框)字段类型为“集成自动化” b)或直接点击功能->终端(ss上的蓝框) 单击settings.json中的任意编辑 将bash.exe的位置输入到"terminal.integrated.shell.windows": " "字段中

注1:由于它是一个JSON文件,请记住在路径中使用双\\而不是\。

注意2:不要混淆bash.exe(它在bin文件夹中)和git-bash.exe,在第一种情况下bash终端将留在VSC中,第二种情况下它将在外部打开。

其他回答

Ctrl+Shift+P >打开用户设置>

"terminal.integrated.profiles.windows": {
    "Git Bash": {
    "path": "D:\\Git\\bin\\bash.exe", 
    "icon": "terminal-bash"
    }
},
"terminal.integrated.defaultProfile.windows": "Git Bash",
"git.enabled": true,
"git.path": "D:\\Git\\bin\\bash.exe",
"terminal.integrated.shell.windows": "D:\\Git\\bin\\bash.exe"

如果您在工作区!

Ctrl+Shift+P >打开工作区设置>在“设置”中粘贴以下内容:{}:

"terminal.integrated.profiles.windows": {
    "Git Bash": {
    "path": "D:\\Git\\bin\\bash.exe",  
    "icon": "terminal-bash"
    }
},
"terminal.integrated.defaultProfile.windows": "Git Bash",
"git.enabled": true,
"git.path": "D:\\Git\\bin\\bash.exe",
"terminal.integrated.shell.windows": "D:\\Git\\bin\\bash.exe"

最后关闭你所有的Vscode窗口/实例,重新打开,你就可以开始了。

关于莱昂布洛伊和灵魂闪耀 解决方案!

从https://git-scm.com/download/win安装Git 打开Visual Studio Code,按住Ctrl + '打开终端。 使用Ctrl + Shift + P打开命令面板。 类型—选择“默认配置文件” 从选项中选择Git Bash 单击终端窗口中的+图标 新终端现在将是Git Bash终端。给它几秒钟来加载Git Bash 现在,您还可以从terminal中的下拉菜单在不同的终端之间切换。

简单地进入设置。在visual studio代码中添加Json,并添加这一行:

  "terminal.integrated.defaultProfile.windows": "Git Bash",

要在Visual Studio Code中打开终端,你不需要在任何地方都使用推荐的Ctrl + ',因为这是非常不方便的手指操作。更好的解决方案是:

Ctrl + j

更新:(2022年6月,VsCode 1.67)

这里的许多答案(就像这个,高度好评)依赖于设置“terminal.integrated.shell.windows”,现在已经弃用了。

还有许多其他的(被接受的)假设Git for Windows在PATH中安装bash.exe -这不是目前推荐/默认的安装选项。

我现在的食谱是:

添加以下到您的设置(Ctrl-Shift-P ->首选项:打开设置(JSON)),替换为您自己的bash路径:

  "terminal.integrated.profiles.windows": {
    "GitBash": {
      "path": "C:\\devel\\Git\\bin\\bash.exe",
      "icon": "terminal-bash"
    }
  },
  "terminal.integrated.defaultProfile.windows": "GitBash",

关闭当前终端,重新启动VsCode。