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


当前回答

将此添加到settings.json中

{
    "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "Git Bash",
            "icon": "terminal-bash"
        },

其他回答

如果你已经有“bash”,“powershell”和“cmd”命令行,并且有正确的路径设置,那么可以通过以下方式从一个命令行切换到另一个命令行。

Ctrl + ':使用默认命令行打开终端窗口。 bash + enter:从默认/当前命令行切换到bash命令行。 powershell + enter:从默认/当前命令行切换到powershell命令行。 cmd + enter:从默认/当前的命令行切换到cmd命令行。

我使用的VS Code版本是1.45.0


您不再需要手动输入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打开终端。你会有巴斯

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

我已经在WSL上设置了很多conda环境(Bash on Ubuntu on Windows),所以我想在Visual Studio Code上使用相同的Bash安装。

要做到这一点,我只需要在Visual Studio Code的设置中指定这个特定的Bash可执行文件(而不是Git-Bash)的路径:

“terminal.integrated.shell.windows”: “C:\\Windows\\System32\\bash.exe”


PS:为了确保你的Ubuntu on Bash可执行文件安装在你的Windows机器上,打开命令提示符(搜索:cmd)并运行:

在bash.exe

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

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

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