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作为外部终端打开一个新的Bash窗口。
如果你想要集成环境,你需要指向Git安装的bin文件夹中的sh.exe文件。
因此,配置应该是C:\\<my-git-install>\\bin\\sh.exe。
我尝试了上面的答案,因为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的文档。
将此添加到settings.json中
{
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "Git Bash",
"icon": "terminal-bash"
},
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",
// ...
}
由于Visual Studio Code的最新更新,事情发生了一些变化。下面的步骤对我有用。
按Ctrl + Shift + P打开Visual Studio Code命令菜单。 在文本区输入>preferences: Open Settings (JSON)。 在JSON文件的末尾添加以下行 右边窗格。 "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe" 关闭并重新打开Visual Studio Code实例。
推荐文章
- 如何设置每个文件类型的标签大小?
- 我如何添加环境变量启动。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 "