【发布时间】:2017-11-10 04:01:03
【问题描述】:
我在我的 Windows 10 PC 上使用 Visual Studio Code。我想将我的默认终端从 Windows PowerShell 更改为 Ubuntu(在 Windows 上)上的 Bash。
我该怎么做?
【问题讨论】:
标签: bash powershell cmd terminal visual-studio-code
我在我的 Windows 10 PC 上使用 Visual Studio Code。我想将我的默认终端从 Windows PowerShell 更改为 Ubuntu(在 Windows 上)上的 Bash。
我该怎么做?
【问题讨论】:
标签: bash powershell cmd terminal visual-studio-code
您也可以通过在 VS Code 中按 F1 并在 VS Code 中输入/选择 Terminal: Select Default Profile(或较旧的 VSCode 版本)。
年长者:
【讨论】:
通过运行终端配置您的默认集成终端:选择默认配置文件命令,也可以通过终端下拉菜单访问。
见https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles
【讨论】:
转到File > Preferences > Settings(或按Ctrl+,)然后点击右上角最左边的图标“打开设置(JSON)”
在 JSON 设置窗口中,添加以下内容(在花括号 {} 内):
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\bash.exe"`
(您也可以在此处放置您想要的任何其他自定义设置)
检查该路径以确保您的 bash.exe 文件在那里,否则找出它的位置并指向该路径。
现在,如果您在 VS Code 中打开一个新的终端窗口,它应该使用 bash 而不是 PowerShell 打开。
【讨论】:
terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
"terminal.integrated.shell.windows" 或 "terminal.integrated.shell.linux" 已弃用,在我的情况下似乎不起作用(Linux 上的 v1.62.0)。请改用"terminal.integrated.defaultProfile.windows" 或"terminal.integrated.shell.linux" 并分别在"terminal.integrated.profiles.windows" 或"terminal.integrated.profiles.linux" 中定义可执行路径。另请参阅下面的@Stephanieraymos 答案。
放弃@arielhad 的解决方案...
我的 VSCode 版本是 1.57.1。
打开 settings.xml 文件:
添加以下内容:
"terminal.integrated.profiles.windows": {
"PowerShell": {
"path": [
"${env:windir}\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
"${env:windir}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
],
"source": "PowerShell",
"icon": "terminal-powershell",
"args": [
"-NoLogo",
"-ExecutionPolicy",
"Bypass"
]
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"icon": "terminal-cmd"
},
//START: THIS DOES NOT WORK
"Git Bash": {
"path": [
"C:\\Program Files\\Git\\bin\\bash.exe",
],
"source": "Git Bash",
"icon": "terminal-bash"
}
// END: THIS DOES NOT WORK
//START: THIS WORKS
"GitBash": {
"path": [
"C:\\Program Files\\Git\\bin\\bash.exe",
],
"icon": "terminal-bash"
}
// END: THIS WORKS
}
我不知道为什么第二种方式有效,但确实有效。看起来“Git Bash”是一个保留名称,我猜你不能设置路径。
【讨论】:
如果要选择控制台的类型,可以在文件“keybinding.json”中写入(该文件可以在以下路径“File->Preferences->Keyboard Shortcuts”中找到) `
//with this you can select what type of console you want
{
"key": "ctrl+shift+t",
"command": "shellLauncher.launch"
},
//and this will help you quickly change console
{
"key": "ctrl+shift+j",
"command": "workbench.action.terminal.focusNext"
},
{
"key": "ctrl+shift+k",
"command": "workbench.action.terminal.focusPrevious"
}`
【讨论】:
集成的 shell 选项仍然有效,但已被贬值。解决方法是改用集成配置文件:
"terminal.integrated.defaultProfile.windows": "C:\\Program Files\\Git\\bin\\bash.exe (migrated)",
"terminal.integrated.profiles.windows": {
"C:\\Program Files\\Git\\bin\\bash.exe (migrated)": {
"path": "C:\\Program Files\\Git\\bin\\bash.exe",
"args": []
}
}
【讨论】:
您可以通过按CTRL SHIFT P打开命令调色板来更改终端
或者您可以转到顶部的查看并单击“打开命令面板”
然后输入Terminal: Select Default Profile
然后你输入你想要的终端。
【讨论】:
由于您使用 WSL,VSCode 具有专用的Remote - WSL 扩展,因此您可以直接在 VSCode 中使用 Linux 环境。在 Linux 中打开项目时,默认使用 Linux 默认 shell(默认为 bash),因此无需配置。
如果您想切换到其他配置文件,有 Terminal > Integrated > Default Profile: Linux 部分,您可以选择自己喜欢的。
【讨论】:
按 ctrl+Shift+p -> 输入 settings.json 在文件中将“powershell”更改为“Git Bash”
【讨论】: