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


当前回答

这取决于你是只在当前用户还是所有用户中安装了Git Bash:

如果所有用户都安装了,那么在用户设置中输入"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe" (Ctrl +逗号)。

如果它只安装在当前用户上,则在用户设置(Ctrl +逗号)中输入“terminal.integrated.shell.windows”:“C:\\Users\\<您的用户>\\AppData\\Local\\Programs\\Git\\bin\\bash.exe”。

如果上面列出的方法不起作用,那么你应该尝试克里斯特的解决方案,它说-

如果你想要集成环境,你需要指向Git安装的bin文件夹中的sh.exe文件。 因此,配置应该是C:\\<my-git-install>\\bin\\sh.exe。

注意:sh.exe和bash.exe在我看来完全一样。它们之间应该没有区别。

其他回答

最新的VS代码:

如果你看不到设置。进入菜单文件->首选项->设置(或按Ctrl+,) 设置出现,见两个选项卡用户(默认选择)和工作空间。进入“用户->功能->终端” 终端部分出现,请参见settings.json中的链接编辑。点击并添加"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe" 保存并重新启动VS代码。

Bash终端将反映在终端上。

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

Ctrl + j

我的VS Code版本:1.56.1 (Code——version)

一体化终端配置的用户设置:

Ctrl + Shift + P 用户类型: 首选项:打开用户设置 点击:打开设置(JSON)按钮(靠近右上角)

settings.json:

{
    "terminal.integrated.tabs.enabled": true,
    "terminal.integrated.shell.windows": "<your installation path>\\Git\\bin\\bash.exe",
    "terminal.integrated.defaultProfile.windows": "Git Bash",
    "terminal.integrated.profiles.windows": {
        "Git Bash": {
            "path": "<your installation path>\\Git\\bin\\bash.exe",
            "icon": "terminal-bash"
        },
        "Command Prompt": {
            "path": "${env:windir}\\System32\\cmd.exe",
            "icon": "terminal-cmd"
        },
        "Windows PowerShell": {
            "path": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
            "icon": "terminal-powershell"
        }
    }
}

terminal.integrated.defaultProfile.windows

这个属性只会在你点击“添加新终端”(“+”)按钮时将GitBash设置为默认值。在启动时将其设置为默认值是不够的。

terminal.integrated.shell.windows

将显示废弃的警告。但是,要使所选shell(这里是github)在启动时成为默认shell,则需要此配置。

过滤问题

在PROBLEMS选项卡上,在输入字段旁边,单击过滤器图标,我选中了“Show Active File Only”选项,以便在处理其他任何事情时消除这个已弃用的错误。

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

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

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

更新:(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。