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


当前回答

对我来说,这是唯一有效的组合!

"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\git-cmd.exe",
"terminal.integrated.shellArgs.windows": [
  "--command=usr/bin/bash.exe",
  "-l",
  "-i"
]

使用git-bash.exe作为…shell。每次在维密外面开派对的时候!!

感谢上帝,它终于成功了!!否则,我打算彻底清除VS并重新安装它(使我重新安装我所有的扩展和重做我的自定义!)

其他回答

Visual Studio Code可以检测并在配置终端菜单中列出已安装的Git Bash:选择默认配置文件,正如许多其他答案已经描述的那样,但这从未发生在我身上。对于那些不像我这么幸运的人,你可以在Visual Studio Code的设置中添加自定义配置文件。json:手动

{
    // Tested in Visual Studio Code version 1.58.2, 1.59.1
    // Notice: my git install path is `D:\Git\bin\bash.exe`

    //"terminal.integrated.shell.windows": "D:\\Git\\bin\\bash.exe",
    // This works fine for me for a long time,
    // but in latest versions this is reported as deprecated,
    // you can keep this and sometimes Visual Studio Code will prompt to help
    // `migrate` it into new setting.

    // This part can be generated by Visual Studio Code
    "terminal.integrated.profiles.windows": {
        // This seems to be a reserved profile name, and also does not work for
        // me
        "Git Bash": {
            "path": "D:\\Git\\bin\\bash.exe",
            "icon": "terminal-bash"
        },
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },

        // Add your custom one with a different profile name from "Git Bash"
        "gitbash": {
            "path": "D:\\Git\\bin\\bash.exe",
            "icon": "terminal-bash"
        }
    },
    // Set the custom profile as default
    "terminal.integrated.defaultProfile.windows": "gitbash",

    // ...
}

在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代码中添加Json,并添加这一行:

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

我已经在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

我恰好是一家财富500强公司的顾问,不幸的是,我用的是Windows 7,没有管理员权限。因此,Node.js, Npm, Visual Studio Code等。被推到我的机器-我不能改变很多,等等…

对于这台运行Windows 7的电脑:

下面是我的新设置。不工作的将被注释掉。

{
    "update.channel": "none",
    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
    //"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe"
}