Windows上的Visual Studio Code默认使用PowerShell作为集成终端。如果你想从Visual Studio Code中使用Bash,应该遵循哪些步骤?
当前回答
Vs代码1.60.0
因为我正面临着前面的问题,Git Bash根本没有被识别,尽管之前已经安装了。要让上述任何解决方案发挥作用,您需要遵循本主题中讨论的说明和下面列出的说明。
转到settings.json 通过添加“git. sh”来启用git bash。启用”:真正的 并通过添加“git”来定义它的路径。path": "<你的路径到GIT>\\ GIT \\bin\\bash.exe"
之后,指令(例如由@rustyhu定义的指令)将起作用。
PS:希望我能在调试最初陈述的问题时为您节省几个小时的时间
其他回答
Vs代码1.60.0
因为我正面临着前面的问题,Git Bash根本没有被识别,尽管之前已经安装了。要让上述任何解决方案发挥作用,您需要遵循本主题中讨论的说明和下面列出的说明。
转到settings.json 通过添加“git. sh”来启用git bash。启用”:真正的 并通过添加“git”来定义它的路径。path": "<你的路径到GIT>\\ GIT \\bin\\bash.exe"
之后,指令(例如由@rustyhu定义的指令)将起作用。
PS:希望我能在调试最初陈述的问题时为您节省几个小时的时间
这取决于你是只在当前用户还是所有用户中安装了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可以检测并在配置终端菜单中列出已安装的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",
// ...
}
(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中,第二种情况下它将在外部打开。
我跟随Paul DeCarlo的教程使用了Windows子系统for Linux (WSL)中的Bash,而不是Git Bash for Windows附带的Bash。它们与上面答案中的步骤相同,但在用户设置中使用下面的步骤。
“终端集成windows shell。”。“C: \ windows \ sysnative \ \ bash . exe”,
这对我来说第一次奏效了。这对这种物质来说很少见。
推荐文章
- 如何设置每个文件类型的标签大小?
- 我如何添加环境变量启动。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 "