VSCode 突然默认为集成终端和任务的 powershell

Ril*_*n42 5 powershell git-bash visual-studio-code

当我今天早上醒来并启动 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": ""
}
Run Code Online (Sandbox Code Playgroud)

我发现这个相关的 SO 帖子制作了默认的 powershell,但我没有看到我的设置有任何不正确的地方......特别是因为我的目标是相反的 - 停止 Powershell!

mkl*_*nt0 47

更新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 实例也会如此。

请参阅GitHub 问题 #132150

以下信息与该错误无关,但希望对于 Visual Studio Code 最近在如何配置集成终端的 shell 方面进行的更改仍然有用的一般信息:


从旧版默认 shell 设置迁移到shell 配置文件

  • 最近,"terminal.integrated.shell.*""terminal.integrated.shellArgs.*"设置 已被弃用,并被更灵活的模型所取代,该模型允许通过所谓的外壳配置文件定义多个外壳以供选择,可以选择在设置中定义,并带有引用默认情况下要使用的配置文件名称的"terminal.integrated.profiles.*"关联强制设置- 这可能是明确定义的自定义配置文件或内置的、适合平台的默认配置文件之一。"terminal.integrated.defaultProfile.*"

    • 注意:*上面的设置中的名称代表相应的平台标识符,即windowslinuxosx(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.*"包含从旧设置的值派生的自定义 shell 配置文件的设置"terminal.integrated.shell.*",如果存在的话"terminal.integrated.shellArgs.*";该自定义配置文件的名称具有后缀 (migrated)
        • 创建terminal.integrated.defaultProfile.*其值为迁移的配置文件名称的设置,使其成为默认 shell。
        • 删除旧设置"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.*中的设置,其值是所选 shell 配置文件的名称 - 可能是内置配置settings.json文件的名称或显式定义的名称之一"terminal.integrated.profiles.*"

    • 注意:默认情况下,此 shell 也用于任务(在 中定义tasks.json),但可以使用"terminal.integrated.automationShell.*"指向替代 shell 的可执行文件的设置来覆盖它。

  • 或者settings.json您可以在您的文件中使用感兴趣的shell 配置文件创建适合平台的terminal.integrated.profiles.*设置

    • 注意:即使您settings.json包含(适合平台的)设置,Visual Studio code 也具有它所知道的内置标准配置文件,并在选择默认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"
          }
        }
        
        Run Code Online (Sandbox Code Playgroud)

您在问题中链接到的答案概述了 Visual Studio Code 中使用的各种类型的 shell,该答案已更新反映有关新 shell 配置文件的信息。


[1] 注意:如果找到PowerShell (Core) v6+安装,它将优先于内置Windows PowerShell版本。


小智 6

注意:现在该错误已在 Visual Studio Code 中修复。只需将您的 Visual Studio Code 更新到最新版本即可。(2021 年 9 月 17 日


我有一个临时解决方案。

首先将此代码粘贴到settings.json中并保存。

"terminal.integrated.defaultProfile.windows": "Git Bash",

"terminal.integrated.profiles.windows": {
 "C:\\Program Files\\Git\\bin\\bash.exe": {
  "path": "",
  "args": []
 }
},
Run Code Online (Sandbox Code Playgroud)

在关闭 Visual Studio Code 之前,选择Output而不是Terminal.

  1. 现在您可以打开 Visual Studio Code
  2. 加载 Visual Studio Code 后,您需要单击“终端”。之后,您将看到Bash
  3. 每次关闭 Visual Studio Code 之前选择输出。

参考:Visual Studio Code 突然默认使用 PowerShell 作为集成终端,而不是 Windows 中的 $Bash

注意: 这不是解决方案。我分享这个是因为也许它可以让你免于失望。


归档时间:

查看次数:

151 次

最近记录:

4 年,9 月 前