【问题标题】:VSCode is suddenly defaulting to powershell for integrated terminal and tasksVSCode 突然默认使用 powershell 来集成终端和任务
【发布时间】:2021-11-02 23:02:39
【问题描述】:

当我今天早上醒来并启动 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": ""
}

我发现这个 related SO post 是默认的 powershell,但我没有看到任何关于我的设置不正确的地方……尤其是因为我的目标是相反的——停止 Powershell!

【问题讨论】:

  • stackoverflow.com/a/69048033/836330 上查看我的Git Bash 设置。您正在使用已弃用的设置形式(但我相信它们仍然可以工作)。但是自 v1.60 版本以来出现了另一个问题 - 请参阅链接。
  • @Mark 你的 git bash 配置效果很好,我使用它然后添加了"terminal.integrated.automationShell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
  • 我以为我疯了;很高兴我不是唯一一个。我必须打开我的settings.json 文件,更改一些内容并再次保存,以便它实际设置默认配置文件。太烦人了,我希望他们能尽快解决这个问题。
  • 我正要为这个错误发疯,因为我有任务在 powershell 和 Git Bash 中运行。在我的设置中添加 "terminal.integrated.automationShell.windows": "C:\\Program Files \\Git\\bin\\bash.exe" 解决了这个问题。现在我的 powershell 任务和 git bash 任务都运行良好。
  • 哦,这破坏了我的“恢复终端”工作流程,我可以确认此错误发生在此更新后

标签: powershell visual-studio-code git-bash


【解决方案1】:

更新版本 v1.60.0 有一个错误。升级到 v1.60.1 或更高版本以进行修复

该错误表现为以下症状

  • 资源管理器窗格快捷方式中的Open in Integrated Terminalshortcut-menu 命令始终使用内置的默认shell(Windows 上的PowerShell),而忽略配置的shell。

  • 运行任务也是如此(有或没有单独的terminal.integrated.automationShell.* 设置)。

  • 另外,如果给定文件夹或工作区在退出 Visual Studio Code 时碰巧打开了集成终端,则在集成终端下次自动重新打开时启动的 shell 再次是内置的默认 shell,而不是配置的一。相比之下,如果重新打开不会自动打开集成终端,手动打开它确实尊重配置的默认 shell,稍后手动创建另一个 shell 实例也是如此。

GitHub issue #132150

事实证明,以下信息与该错误无关,但希望仍然是有关 Visual Studio Code 最近更改集成终端的 shell 配置的有用一般信息:


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

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

    • 注意:以上设置名称中的* 代表相应的平台标识符,即windowslinuxosx (macOS)。
  • 从 v1.60.1 开始,如果旧版 "terminal.integrated.shell.*" 设置 存在,则 设置优先(即使在 @ 中编辑 "terminal.integrated.shell.*" 时的工具提示987654339@ 表明这种变化尚未到来)。

    • 在没有 both 设置的情况下,使用 Visual Studio Code 的 内置 默认 shell,它在 WindowsPowerShell[1] 并且在 类 Unix 平台上是用户的默认 shell,如 SHELL 环境变量中指定

    • 最近的 Visual Studio Code 版本,从 之前 v1.60 开始 - 似乎是一次一次性 机会 - 显示了一个提示提供迁移已弃用的设置改为新设置。

      • 接受迁移结果如下:

        • 创建设置"terminal.integrated.shell.*",其中包含从旧设置"terminal.integrated.shell.*""terminal.integrated.shellArgs.*" 的值派生的自定义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:

    • 单击集成终端右侧的shell-selector图标()的向下箭头部分,选择Select Default Profile,它会显示已定义配置文件的列表以从-中选择默认值如果没有明确定义的配置文件,则提供标准配置文件(见下文)。

    • 这转化为settings.json 中的terminal.integrated.defaultProfile.* 设置,其值是所选shell 配置文件的名称——可能是内置 配置文件的名称或其中之一在"terminal.integrated.profiles.*"中明确定义

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

  • (可选),在您的 settings.json 文件中,您可以使用感兴趣的shell profiles 创建一个适合平台的terminal.integrated.profiles.* 设置

    • 注意:即使您的 settings.json 包含 no(适合平台)"terminal.integrated.profiles.*" 设置,Visual Studio 代码也有它知道的内置 standard 配置文件,并且在选择 default shell 时提供它们以供选择。

      • 这些标准配置文件是主机平台随附的 shell 以及 Visual Studio 在给定系统上动态检测到的一些 shell,例如 Windows 上的 Git Bash。
    • 创建标准配置文件显式,请执行以下操作:

      • 注意:您可以选择这样做以自定义标准配置文件。但是,如果您的意图只是添加自定义配置文件 - 请参阅 this answer 示例 - 没有必要在 "terminal.integrated.profiles.*" 设置中创建标准配置文件,因为 Visual Studio Code 知道即使没有明确定义。

      • 通过File > Preferences > Settings (Ctrl-,),搜索profiles 并点击平台对应的Terminal > Integrated > Profiles > * 设置下方的Edit in settings.json;这将打开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"
          }
        }
        

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


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

【讨论】:

    【解决方案2】:

    编辑:1

    注意:现在这个错误已经被 VSCode 修复了。只需将您的 VSCode 更新到最新版本。 (2021 年 9 月 17 日


    我有一个临时解决方案。

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

    "terminal.integrated.defaultProfile.windows": "Git Bash",
    
    "terminal.integrated.profiles.windows": {
     "C:\\Program Files\\Git\\bin\\bash.exe": {
      "path": "",
      "args": []
     }
    },
    

    在关闭 VSCode 之前选择 Output 而不是 Terminal

    1. 现在您可以打开 VSCode
    2. 加载VSCode后,需要点击终端。在此之后,您现在将看到 bash。
    3. 在关闭 VSCode 之前选择输出。

    参考:VSCode is suddenly defaulting to PowerShell for integrated terminal instead of $Bash in Windows

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

    这是我的第一篇文章,如果有任何错误,请告诉我,以便我更正。

    【讨论】:

      【解决方案3】:

      您可以随时从官网https://code.visualstudio.com/updates/v1_59(目前在顶部)下载并安装以前的版本。

      由于 1.60 版本存在漏洞,v1.59 是一个不错的候选版本。

      禁用自动更新

      解释here

      1. 打开用户设置File > Preferences > Settings
      2. "update.mode": "none" 添加到您的设置中。

      安装旧版本

      之后,您可以使用下载的版本安装覆盖当前版本。

      注意:请等待下一个版本修复它,所以请记住您已禁用自动更新!

      【讨论】:

      • 当您安装旧版本时,请确保放回此设置 "terminal.integrated.shell.windows": "C:\\\\bin\\bash.exe"
      • 我只是照常安装了 v1.59,我不需要在 json 设置中添加任何东西,它可以完美运行
      【解决方案4】:

      我有同样的问题,但我尝试运行命令提示符。我通过添加到 ...\Code\User\settings.json

      来修复它

      "terminal.integrated.automationShell.windows": "cmd.exe",

      【讨论】:

        【解决方案5】:

        只需在 settings.json 中用 Git Bash 替换 CMD :-)

        "terminal.integrated.profiles.windows": {
            "PowerShell": {
                "source": "PowerShell",
                "icon": "terminal-powershell"
            },
            "Command Prompt": {
                "path": [
                    //"${env:windir}\\Sysnative\\cmd.exe",
                    //"${env:windir}\\System32\\cmd.exe"
                    "C:\\PrivateProgramms\\Git\\bin\\bash.exe"
                ],
                "args": [],
                "icon": "terminal-cmd"
            },
           "Git Bash": {
                "source": "Git Bash"
                //"path": [  "C:\\PrivateProgramms\\Git\\bin\\bash.exe" ],
                //"args": [],
                //"icon": "terminal-cmd"
            }
        },
        "terminal.integrated.defaultProfile.windows": "Command Prompt"
        

        【讨论】:

          猜你喜欢
          • 2021-11-04
          • 1970-01-01
          • 2019-08-22
          相关资源
          最近更新 更多