powershell - VSCode 突然默认使用 powershell 来集成终端和任务
问题描述
当我今天早上醒来并启动 VSCode 时,我的默认终端在启动时,运行任务时现在是 powershell,而不是 Git Bash。我在窗户上。我尝试更改 settings.json 无济于事。有什么我想念的吗?
{
"workbench.startupEditor": "newUntitledFile",
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"[javascript]": {
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
},
"aws.samcli.location": "C:\\Users\\king\\AppData\\Roaming\\npm\\sam.exe",
"typescript.updateImportsOnFileMove.enabled": "always",
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
},
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"javascript.updateImportsOnFileMove.enabled": "always",
"explorer.confirmDragAndDrop": false,
"diffEditor.maxComputationTime": 0,
"extensions.ignoreRecommendations": true,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.renderControlCharacters": true,
"[jsonc]": {
"editor.quickSuggestions": {
"strings": true
},
"editor.suggest.insertMode": "replace"
},
"window.zoomLevel": 0,
"editor.accessibilitySupport": "off",
"workbench.editor.untitled.hint": "hidden",
"terminal.integrated.defaultProfile.windows": "Git Bash",
"terminal.external.windowsExec": "C:\\Program Files\\Git\\bin\\bash.exe",
"terminal.explorerKind": "external",
"terminal.integrated.automationShell.linux": ""
}
我发现这个相关的 SO 帖子制作了默认的 powershell,但我没有看到任何关于我的设置不正确的地方……尤其是因为我的目标是相反的——停止 Powershell!
解决方案
更新:版本 v1.60.0 有一个错误。升级到 v1.60.1 或更高版本进行修复。
该错误表现为以下症状:
资源管理器窗格的快捷方式中的
Open in Integrated Terminal
快捷方式菜单命令始终使用内置的默认 shell(Windows 上的 PowerShell),而忽略已配置的 shell。运行任务也是如此(有或没有单独的
terminal.integrated.automationShell.*
设置)。此外,如果给定文件夹或工作区在退出 Visual Studio Code 时碰巧打开了集成终端,则在集成终端下次自动重新打开时启动的 shell 再次是内置的默认 shell,而不是配置的 shell。相比之下,如果重新打开不会自动打开集成终端,则手动打开它会尊重配置的默认 shell,稍后手动创建另一个 shell 实例也是如此。
以下信息与该错误无关,但希望仍然是有关 Visual Studio Code 最近更改集成终端的 shell 配置的有用一般信息:
从旧的默认 shell 设置迁移到shell 配置文件:
最近,
"terminal.integrated.shell.*"
and"terminal.integrated.shellArgs.*"
设置已被弃用,取而代之的是一个更灵活的模型,该模型允许通过所谓的shell配置文件(可选地在 setting 中定义)定义多个shell 以从中进行选择"terminal.integrated.profiles.*"
,并带有一个关联的强制设置,该设置引用默认情况下"terminal.integrated.defaultProfile.*"
要使用的配置文件的名称- 这可能是明确定义的自定义配置文件或内置的、适合平台的默认配置文件之一。- 注意:
*
在上面的设置中,names 代表相应的平台标识符,即windows
,linux
, 或osx
(macOS)。
- 注意:
从 v1.60.1 开始,如果还存在旧
"terminal.integrated.shell.*"
设置,则新设置优先(即使在编辑时的工具提示表明此更改尚未到来)。"terminal.integrated.shell.*"
settings.json
在没有这两种设置的情况下,使用Visual Studio Code 的内置默认 shell,在Windows上是PowerShell [ 1],在类 Unix 平台上使用用户的默认 shell,在
SHELL
环境变量中指定。最近的 Visual Studio Code 版本,从v1.60开始- 似乎是一次性的机会 - 显示了将弃用设置迁移到新设置的提示。
接受迁移会导致以下结果:
- 创建
"terminal.integrated.shell.*"
包含从旧设置的值派生的自定义外壳配置文件的设置"terminal.integrated.shell.*"
,如果存在,则"terminal.integrated.shellArgs.*"
;该自定义配置文件的名称具有后缀(migrated)
- 创建设置
terminal.integrated.defaultProfile.*
,其值为迁移的配置文件的名称,使其成为默认外壳。 - 删除旧设置
"terminal.integrated.shell.*"
和"terminal.integrated.shellArgs.*"
- 创建
如果您拒绝迁移,您可以稍后通过重新选择默认 shell 来有效地执行迁移,如下所述。
- 注意:
"terminal.integrated.defaultProfile.*"
在此过程中创建的新设置会有效地覆盖旧设置"terminal.integrated.shell.*"
和"terminal.integrated.shellArgs.*"
设置,但不会自动删除后者。为避免混淆,最好settings.json
手动删除它们。
- 注意:
选择要使用的默认 shell 配置文件以(重新)指定默认 shell:
单击集成终端右侧的外壳选择器图标 ( ) 的向下箭头部分,选择
Select Default Profile
,它会显示已定义配置文件的列表,以从中选择默认配置 - 在没有明确定义的配置文件的情况下,标准配置文件提供(见下文)。这转换为 中的
terminal.integrated.defaultProfile.*
设置settings.json
,其值是所选 shell 配置文件的名称 - 这可能是内置配置文件的名称或在中明确定义的配置文件之一"terminal.integrated.profiles.*"
注意:默认情况下,此 shell 也用于任务(在 中定义
tasks.json
),但可以使用"terminal.integrated.automationShell.*"
指向替代 shell 的可执行文件的设置来覆盖。
或者,在您的
settings.json
文件中,您可以使用感兴趣的shell 配置文件创建适合平台的terminal.integrated.profiles.*
设置:注意:即使您不
settings.json
包含(适合平台的)设置,Visual Studio 代码也有它知道的内置标准配置文件,并在选择默认shell 时提供它们以供选择。"terminal.integrated.profiles.*"
- 这些标准配置文件是主机平台附带的 shell 以及 Visual Studio 在给定系统上动态检测到的一些 shell,例如 Windows 上的 Git Bash。
要显式创建标准配置文件,请执行以下操作:
注意:您可以选择这样做以自定义标准配置文件。但是,如果您的意图只是添加自定义配置文件(请参阅此答案以获取示例),则无需在
"terminal.integrated.profiles.*"
设置中创建标准配置文件,因为即使未明确定义,Visual Studio Code 也知道它们。通过
File > Preferences > Settings
( ),在平台相应设置下方Ctrl-,搜索profiles
并单击;这将打开以供编辑,并添加标准配置文件;只需保存文件就足够了。Edit in settings.json
Terminal > Integrated > Profiles > *
settings.json
- 注意:如果
"terminal.integrated.profiles.*"
显示的设置不包含预期的、适合平台的标准配置文件,则可能已经存在同名的设置;要强制创建标准配置文件,请删除或注释掉现有设置并保存文件,然后重试。
- 注意:如果
在 Windows 上,您最终会得到如下内容:
"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": { "source": "Git Bash" } }
您在问题中链接到的答案提供了Visual Studio Code 中使用的各种类型的 shell 的概述,已更新以反映有关新 shell 配置文件的信息。
[1] 注意:如果找到PowerShell (Core) v6+安装,它优先于内置的Windows PowerShell版本。
推荐阅读
- sed - sed:仅在包含单词 z 的行上将所有出现的单词 X 替换为 Y
- javascript - 如果我们在网页上有多个表单,action 属性的值应该是多少?
- junit5 - 如何使用 assertThrows
- html - 这在 chrome 开发者工具中意味着什么
- axlsx - caxlsx / axlsx 数据透视表忽略空白并删除总计
- javascript - 是否有 openweathermap 的完整 JSON 响应的示例?
- python - 在 google ortools 中添加析取约束
- geth - GETH 如何达到 TX 的最大广播速度
- css - 使用 Angular 重新触发 css 动画
- r - 安装 xfun 的问题(对于 rmarkdown)