【发布时间】:2021-11-01 12:44:58
【问题描述】:
每当我在 VS Code 中打开终端时,它总是打开它的默认终端,我总是必须手动更改它。
这真的很烦人,因为我每天都在使用终端。我检查了工具栏中的Terminal 设置,但找不到更改默认值的选项。我们该怎么做?
【问题讨论】:
标签: visual-studio-code terminal vscode-settings
每当我在 VS Code 中打开终端时,它总是打开它的默认终端,我总是必须手动更改它。
这真的很烦人,因为我每天都在使用终端。我检查了工具栏中的Terminal 设置,但找不到更改默认值的选项。我们该怎么做?
【问题讨论】:
标签: visual-studio-code terminal vscode-settings
github 上有很多关于此的问题,请参阅,例如,Default console changed from what I wanted to Powershell during upgrade (我认为这是 v1.60 版本中最古老的跟踪问题)。
我可以在 Stable v1.60 版本中复制该问题,但不能在 Insiders' 版本中使用完全相同的设置。
所以这不是您的设置,我相信 vscode 团队知道这一点。您的选择是
(1) 使用 Insiders' Build - 至少对我有用,
(2) 将vscode降级到v1.59,
(3) 当我点击 Add Terminal + 按钮时,我确实得到了我的默认 Git Bash 终端,或者
(4) 重命名您的默认配置文件 - 见下文。
仅供参考,我的设置:
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
// "Git Bash": { // "Git Bash" does not work
"GitBash": { // "GitBash" does work
"path": "C:\\Program Files\\Git\\bin\\bash.exe",
"icon": "terminal-bash"
}
},
// "terminal.integrated.defaultProfile.windows": "Git Bash" // does not work for me
"terminal.integrated.defaultProfile.windows": "GitBash" // does work
// deprecated but may still work for you
// "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
以前trying to set Git Bash as default profile,对于Git Bash,建议改用GitBash(去掉空格)。直到今天在 v1.60 稳定版本中,这对我来说从来没有用过。
因此,如果不起作用,可以尝试将您的个人资料名称更改为 Git Bash 或 WSL 等以外的名称。
【讨论】:
我已经尝试设置默认终端大约十几次,但它并没有坚持最新的更新。它一直打开 PowerShell 作为默认终端。这些设置对我来说一直很好,直到昨天的更新 (v1.60.0) 打破了这一点。
"terminal.integrated.defaultProfile.windows": "WSL",
"terminal.integrated.profiles.windows": {
"WSL": {
"path": "C:\\WINDOWS\\System32\\wsl.exe",
"args": [
"~"
],
"icon": "terminal-ubuntu"
},
"Git Bash": {
"source": "Git Bash",
"icon": "terminal-bash"
},
"Command Prompt": {
"path": [
"${env:windir}\\System32\\cmd.exe"
],
"args": ["/K cls && cd /D C:\\OD"],
"icon": "terminal-cmd"
},
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
}
}
还有其他人遇到过这种情况吗?
【讨论】:
我让它正确加载,但是当我尝试使用运行按钮运行 Python 脚本时,它在 PowerShell 中运行。
"terminal.integrated.automationShell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"terminal.external.windowsExec": "C:\\Program Files\\Git\\bin\\bash.exe",
"terminal.integrated.profiles.windows": {
"PowerShell": null,
"Command Prompt": null,
"Git Bash": {
"path": "C:\\Program Files\\Git\\bin\\bash.exe",
"icon": "terminal-bash"
},
},
"terminal.integrated.defaultProfile.windows": "Git Bash"
【讨论】:
对我有用的解决方案是:
方法一:
打开Settings.json文件并添加以下代码行
"terminal.integrated.defaultProfile.windows": "Command Prompt"
进行此更改后,我的Settings.json 文件如下所示:
{
"files.autoSave": "afterDelay",
"window.zoomLevel": 1,
"liveServer.settings.donotVerifyTags": true,
"liveServer.settings.donotShowInfoMsg": true,
"terminal.integrated.automationShell.windows": "",
"terminal.integrated.automationShell.linux": "",
"terminal.integrated.defaultProfile.windows": "Command Prompt"
}
方法二:
点击Settings并搜索defaultprofilewindows
您将在此选项卡上获得默认终端。点击菜单列表,选择Command Prompt。
您可以选择任何可用的终端并检查哪一个可以根据需要工作。
注意:使用任何一种方法都会得到相同的结果。上述两种方法对我来说都非常有效。
【讨论】: