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


当前回答

这个答案与投票最多的答案相似,但有一个重要的区别:之前关于这个问题的很多答案都集中在运行Git Bash上,而我的答案则集中在运行WSL Bash上。

在Windows 10机器上启用Windows子系统for Linux。 打开Visual Studio Code,按住Ctrl + '打开终端。 使用Ctrl + Shift + P打开命令面板。 类型—选择“Default Shell”。 从选项中选择WSL Bash(不是Git Bash)。

单击终端窗口中的+图标。新终端现在将是一个WSL Bash终端!

其他回答

Vs代码1.60.0

因为我正面临着前面的问题,Git Bash根本没有被识别,尽管之前已经安装了。要让上述任何解决方案发挥作用,您需要遵循本主题中讨论的说明和下面列出的说明。

转到settings.json 通过添加“git. sh”来启用git bash。启用”:真正的 并通过添加“git”来定义它的路径。path": "<你的路径到GIT>\\ GIT \\bin\\bash.exe"

之后,指令(例如由@rustyhu定义的指令)将起作用。

PS:希望我能在调试最初陈述的问题时为您节省几个小时的时间

我尝试了上面的答案,因为vscode 1.42.1和他们的工作,让我一个git bash终端。因此,这个设置只适用于从终端打开bash shell:

"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"

然而,它也有一个不想要的副作用,即它也是用于构建东西的shell,这打破了MS c++链,因为用于路径分隔符的\字符被bash理解为转义字符。对我来说,完整的修复需要我添加这个额外的变量,将其设置为powershell:

"terminal.integrated.automationShell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"

现在,我可以有我的bash终端和Ctrl-Shift-B或F5工作没有问题。

哦,正如其他海报提到的,这些信息的来源是VSCode的文档。

在2022年7月,我通过在花括号内添加以下内容来解决这个问题。

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

注意Git和Bash之间的空白。

我的设置。Json是这样的:

{
    "python.defaultInterpreterPath": "C:\\Users\\Prakh\\AppData\\Local\\Programs\\Python\\Python39\\python.exe",
    "python.diagnostics.sourceMapsEnabled": true,
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true,
    "code-runner.runInTerminal": true,
    "terminal.integrated.defaultProfile.windows": "Git Bash"
}

现在重新启动VS code并关闭所有现有终端并打开一个新终端。

由于Visual Studio Code的最新更新,事情发生了一些变化。下面的步骤对我有用。

按Ctrl + Shift + P打开Visual Studio Code命令菜单。 在文本区输入>preferences: Open Settings (JSON)。 在JSON文件的末尾添加以下行 右边窗格。 "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe" 关闭并重新打开Visual Studio Code实例。

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窗口/实例,重新打开,你就可以开始了。

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