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


当前回答

对于scoop用户:

"terminal.integrated.shell.windows": "C:\\Users\\[YOUR-NAME]\\scoop\\apps\\git\\current\\usr\\bin\\bash.exe",
"terminal.integrated.shellArgs.windows": [
  "-l",
  "-i"
],

其他回答

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

Ctrl + j

您不再需要手动输入bash.exe路径。这个答案不赞成。现在,如果在默认路径中安装了git,可以直接切换到bash。如果将git安装到不同的路径,则需要使用下面的解决方案。


从https://git-scm.com/download/win安装Git。

然后打开Visual Studio Code,使用Ctrl + Shift + p打开命令面板,然后输入“open user setting”,然后从下拉菜单中选择“open user Settings”。

然后这个选项卡会打开,左边是默认设置,右边是你的设置:

现在将这行代码复制到您自己的设置页面(右侧的窗格)并保存 "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"

注意:“C:\\Program Files\Git\bin\bash.exe”是Git安装时bash.exe文件所在的路径。如果您使用的是Windows子系统for Linux (WSL) Bash shell,路径将是“C:\Windows\System32\ Bash .exe”

现在按Ctrl + '从Visual Studio Code打开终端。你会有巴斯

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

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

按住Ctrl + '打开终端。 在终端中,输入bash在终端中使用Git bash。 注意:确保在您的机器上安装了Git Bash。

如果您想再次使用PowerShell,只需在终端中输入PowerShell即可。要使用Windows命令行,在终端中输入cmd。

您选择的设置将被用作默认设置。

(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中,第二种情况下它将在外部打开。