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


当前回答

在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并关闭所有现有终端并打开一个新终端。

其他回答

在最新的稳定版本中,即1.54,禁用ConPTY解决了我的问题。我写这篇文章是希望它也能解决你的问题。

{

 "terminal.integrated.shell.windows": "C:\\path\\to\\bin\\bash.exe",
 "terminal.integrated.windowsEnableConpty": false
}

更新:较新版本的Visual Studio Code在终端下拉菜单中有选择默认Shell命令:

记住,它只是列出了%PATH%环境变量中的shell。对于不在路径上的shell,请参阅其他答案。

额外提示:当你启动bash时,它只会执行.bashrc,如果你在.bash_profile中有初始化命令,你必须将它复制到.bashrc。在Git Bash中使用Conda环境是必不可少的。

1.36版本之前(2019年6月)

现在最简单的方法(至少从Visual Studio Code 1.22开始)是按Shift + Ctrl + P打开命令面板,然后输入:

Select Default Shell

现在你可以很容易地在路径中选择你喜欢的shell:

对于不在%PATH%中的shell,请参阅其他答案。

参见完整的Visual Studio Code shell参考。有很多肉的东西。

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

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

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

我跟随Paul DeCarlo的教程使用了Windows子系统for Linux (WSL)中的Bash,而不是Git Bash for Windows附带的Bash。它们与上面答案中的步骤相同,但在用户设置中使用下面的步骤。

“终端集成windows shell。”。“C: \ windows \ sysnative \ \ bash . exe”,

这对我来说第一次奏效了。这对这种物质来说很少见。

在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并关闭所有现有终端并打开一个新终端。