Windows上的Visual Studio Code默认使用PowerShell作为集成终端。如果你想从Visual Studio Code中使用Bash,应该遵循哪些步骤?
当前回答
对于scoop用户:
"terminal.integrated.shell.windows": "C:\\Users\\[YOUR-NAME]\\scoop\\apps\\git\\current\\usr\\bin\\bash.exe",
"terminal.integrated.shellArgs.windows": [
"-l",
"-i"
],
其他回答
(2021, VSC v.1.55.1)
如何添加Git Bash为默认终端,对于那些安装他们的Git Bash不是在默认路径:
在Visual Studio Code中使用Ctrl +打开设置, a)在“搜索设置”(截图中红框)字段类型为“集成自动化” b)或直接点击功能->终端(ss上的蓝框) 单击settings.json中的任意编辑 将bash.exe的位置输入到"terminal.integrated.shell.windows": " "字段中
注1:由于它是一个JSON文件,请记住在路径中使用双\\而不是\。
注意2:不要混淆bash.exe(它在bin文件夹中)和git-bash.exe,在第一种情况下bash终端将留在VSC中,第二种情况下它将在外部打开。
VSCODE 1.63.2
即使把这里的答案结合起来,我也不能让它工作。也许,我有一个奇异的设置。我会得到这个错误,设置"terminal.integrated.defaultProfile.windows": "Git Bash",它仍然只会打开Powershell, Git Bash无处可见:
我的解决方法是修改命令提示符的入口,通过改变它指向bash的路径,然后将其设置为默认值,如下所示:
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"C:\\Path\\To\\Git\\bin\\bash.exe",
// "${env:windir}\\Sysnative\\cmd.exe",
// "${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"terminal.integrated.defaultProfile.windows": "Command Prompt",
如果你已经有“bash”,“powershell”和“cmd”命令行,并且有正确的路径设置,那么可以通过以下方式从一个命令行切换到另一个命令行。
Ctrl + ':使用默认命令行打开终端窗口。 bash + enter:从默认/当前命令行切换到bash命令行。 powershell + enter:从默认/当前命令行切换到powershell命令行。 cmd + enter:从默认/当前的命令行切换到cmd命令行。
我使用的VS Code版本是1.45.0
我的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”选项,以便在处理其他任何事情时消除这个已弃用的错误。
我尝试了上面的答案,因为vscode 1.42.1和他们的工作,让我一个git bash终端。因此,这个设置只适用于从终端打开bash shell:
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
然而,它也有一个不想要的副作用,即它也是用于构建东西的shell,这打破了MS c++链,因为用于路径分隔符的\字符被bash理解为转义字符。对我来说,完整的修复需要我添加这个额外的变量,将其设置为powershell:
"terminal.integrated.automationShell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
现在,我可以有我的bash终端和Ctrl-Shift-B或F5工作没有问题。
哦,正如其他海报提到的,这些信息的来源是VSCode的文档。
推荐文章
- 如何设置每个文件类型的标签大小?
- 我如何添加环境变量启动。VSCode中的json
- 如何格式化Visual Studio Code项目中的所有文件?
- Pylint在Visual Studio代码中“未解决的导入”错误
- 如何在VS Code中默认打开文本换行
- Git bash错误:无法fork子进程:没有可用的终端(-1)
- 在Visual Studio代码中更改突出显示文本的颜色
- Visual studio代码-键盘快捷键-全部展开/折叠
- Visual Studio Code无法检测已安装的Git
- 禁用Visual Studio代码中的工具提示提示
- Visual Studio Code -将空格转换为制表符
- 在VSCode中的列自动硬换行
- Visual Studio Code:格式没有使用缩进设置
- 如何排除文件扩展名和语言从“格式保存”在VSCode?
- Visual Studio代码- URI的目标不存在" package:flutter/material.dart "