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


当前回答

我恰好是一家财富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"
}

其他回答

我的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”选项,以便在处理其他任何事情时消除这个已弃用的错误。

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

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

这取决于你是只在当前用户还是所有用户中安装了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在我看来完全一样。它们之间应该没有区别。

至少对我来说,这将使Visual Studio Code作为外部终端打开一个新的Bash窗口。

如果你想要集成环境,你需要指向Git安装的bin文件夹中的sh.exe文件。

因此,配置应该是C:\\<my-git-install>\\bin\\sh.exe。

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

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

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