Windows上的Visual Studio Code默认使用PowerShell作为集成终端。如果你想从Visual Studio Code中使用Bash,应该遵循哪些步骤?
当前回答
从https://git-scm.com/download/win安装Git 打开Visual Studio Code,按住Ctrl + '打开终端。 使用Ctrl + Shift + P打开命令面板。 类型—选择“默认配置文件” 从选项中选择Git Bash 单击终端窗口中的+图标 新终端现在将是Git Bash终端。给它几秒钟来加载Git Bash 现在,您还可以从terminal中的下拉菜单在不同的终端之间切换。
其他回答
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",
// ...
}
如果你已经有“bash”,“powershell”和“cmd”命令行,并且有正确的路径设置,那么可以通过以下方式从一个命令行切换到另一个命令行。
Ctrl + ':使用默认命令行打开终端窗口。 bash + enter:从默认/当前命令行切换到bash命令行。 powershell + enter:从默认/当前命令行切换到powershell命令行。 cmd + enter:从默认/当前的命令行切换到cmd命令行。
我使用的VS Code版本是1.45.0
(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中,第二种情况下它将在外部打开。
我恰好是一家财富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代码1.60.0
因为我正面临着前面的问题,Git Bash根本没有被识别,尽管之前已经安装了。要让上述任何解决方案发挥作用,您需要遵循本主题中讨论的说明和下面列出的说明。
转到settings.json 通过添加“git. sh”来启用git bash。启用”:真正的 并通过添加“git”来定义它的路径。path": "<你的路径到GIT>\\ GIT \\bin\\bash.exe"
之后,指令(例如由@rustyhu定义的指令)将起作用。
PS:希望我能在调试最初陈述的问题时为您节省几个小时的时间
推荐文章
- 如何设置每个文件类型的标签大小?
- 我如何添加环境变量启动。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 "