Windows上的Visual Studio Code默认使用PowerShell作为集成终端。如果你想从Visual Studio Code中使用Bash,应该遵循哪些步骤?
当前回答
至少对我来说,这将使Visual Studio Code作为外部终端打开一个新的Bash窗口。
如果你想要集成环境,你需要指向Git安装的bin文件夹中的sh.exe文件。
因此,配置应该是C:\\<my-git-install>\\bin\\sh.exe。
其他回答
将Git\bin目录添加到Path环境变量中。默认目录为%ProgramFiles%\Git\bin。通过这种方式,你可以在每个终端(包括Visual Studio Code的集成终端)中输入Bash即可访问Git Bash。
Windows下如何设置路径和环境变量
我已经在WSL上设置了很多conda环境(Bash on Ubuntu on Windows),所以我想在Visual Studio Code上使用相同的Bash安装。
要做到这一点,我只需要在Visual Studio Code的设置中指定这个特定的Bash可执行文件(而不是Git-Bash)的路径:
“terminal.integrated.shell.windows”: “C:\\Windows\\System32\\bash.exe”
PS:为了确保你的Ubuntu on Bash可执行文件安装在你的Windows机器上,打开命令提示符(搜索:cmd)并运行:
在bash.exe
在2022年7月,我通过在花括号内添加以下内容来解决这个问题。
"terminal.integrated.defaultProfile.windows": "Git Bash"
注意Git和Bash之间的空白。
我的设置。Json是这样的:
{
"python.defaultInterpreterPath": "C:\\Users\\Prakh\\AppData\\Local\\Programs\\Python\\Python39\\python.exe",
"python.diagnostics.sourceMapsEnabled": true,
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"code-runner.runInTerminal": true,
"terminal.integrated.defaultProfile.windows": "Git Bash"
}
现在重新启动VS code并关闭所有现有终端并打开一个新终端。
我的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”选项,以便在处理其他任何事情时消除这个已弃用的错误。
对我来说,这是唯一有效的组合!
"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并重新安装它(使我重新安装我所有的扩展和重做我的自定义!)
推荐文章
- 打开同一目录两次
- 如何从终端/命令行调用VS代码编辑器
- 试图在Windows 10上运行Python时出现“权限被拒绝”
- 如何在Visual Studio代码中重置设置?
- 如何将制表符转换为空格,反之亦然,在现有的文件
- GitHub -致命:无法读取用户名https://github.com':没有这样的文件或目录
- 错误:'types'只能在.ts文件中使用- Visual Studio Code使用@ts-check
- Visual Studio Code: .git文件夹/文件隐藏
- Visual Studio Code:如何调试Python脚本的参数
- 如何在Visual Studio代码中触发参数提示?
- 在VS Code中禁用“Comments are not allowed In JSON”错误
- 使用正则表达式搜索和替换Visual Studio代码
- 如何缩进/格式选择的代码在Visual Studio代码?
- 如何禁用预览文件与点击在vs代码?
- Visual Studio代码更改文件资源管理器托盘的字体大小?