【问题标题】:The new way to configure default shell and argument commands in VSCode?在 VSCode 中配置默认​​ shell 和参数命令的新方法?
【发布时间】:2021-08-08 13:45:29
【问题描述】:

几天前我假设微软发布了一个新的 VSCode 更新,当我开始构建我的 esp idf 项目时它没有工作,因为它依赖于从终端运行的命令,然后它是“特殊”项目构建命令执行后我得出的结论是,以下自动允许的设置位于“设置”中的文件 main.code.workspace 中:

    "terminal.integrated.shell.windows": "cmd.exe",
    "terminal.integrated.shellArgs.windows": [

        "/k", 
        "C:/Coding/ESP32/esp-idf/export.bat"
    ],

报错如下:

这已被弃用,配置默认 shell 的新推荐方法是在 #terminal.integrated.profiles.osx# 中创建终端配置文件并将其配置文件名称设置为 #terminal.integrated.defaultProfile.osx# 中的默认值。这目前将优先于新的配置文件设置,但将来会发生变化。

在启动时配置默认终端并运行此命令的新方法是什么?

【问题讨论】:

    标签: visual-studio-code terminal


    【解决方案1】:

    在 settings.json 文件中我们需要有以下内容

    "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"
        }
    },
    

    并通过添加设置默认终端

    "terminal.integrated.defaultProfile.windows": "Command Prompt",
    

    我们可以通过按 Ctrl + Shift + P 并搜索 Terminal: Select Default Profile 并选择所需的 shell 来实现。

    但是,尽管您当前拥有的设置已弃用,但现在应该可以使用。

    【讨论】:

    • 谢谢,我已将此代码块添加到我的 main.code-workspace 文件中,因此每次加载工作区时它都会执行,但是如何让它在启动时自动键入这两个命令?:“/ k", "C:/Coding/ESP32/esp-idf/export.bat"
    • 我相信您可以像 comment 那样将它添加到 args 字段中,以便它每次都执行。
    • 这是正确答案,但更简单,因为您只需要"terminal.integrated.defaultProfile.windows": "Command Prompt"。这是因为第一个代码块中写入的所有内容都是默认设置(除非您想更改默认设置...)
    【解决方案2】:

    我已经解决了这个问题

    1)将Git/bin添加到环境变量中的路径

    2)重启VSC并在settings.json中添加以下内容

    "terminal.integrated.profiles.windows": {
        "PowerShell": { "source": "PowerShell", "icon": "terminal-powershell" },
        "Command Prompt": {
          "path": [
            "${env:windir}\\Sysnative\\cmd.exe",
            "${env:windir}\\System32\\cmd.exe"
          ],
          "icon": "terminal-cmd"
        },
        "GitBash": {
          "path": ["F:\\Program files\\Git\\bin\\bash.exe"],
          "icon": "terminal-bash"
        },
    },
    "terminal.integrated.defaultProfile.windows": "GitBash",
    

    只需在“GitBash”的路径中替换“你的 git bash 路径”

    3)删除旧设置

    对我来说是

    "terminal.integrated.shell.windows": "F:\\Program files\\Git\\bin\\bash.exe"
    

    4)保存设置,按delete关闭VSC终端,重启VSC

    希望这行得通!

    【讨论】:

    • 非常感谢老兄。这是最简单的方法。真的很感激。不知道为什么它不是批准的答案。
    【解决方案3】:

    我最近在 windows 上升级到 VSCode 1.60 并且遇到了类似的问题 我在配置文件中添加了上面提到的“GitBash”选项,但是当我尝试像这样使用它时:

       "terminal.integrated.defaultProfile.windows": "GitBash",
    

    VSCode 抱怨“GitBash”不是有效值:

    Value is not accepted. Valid values: "PowerShell", "Command Prompt", "JavaScript Debug Terminal".
    

    因此,我更新了“命令提示符”配置文件以指向我的 git bash 并且这个 WORKED

        "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
          },
          "Command Prompt": {
            "path": [
              "C:\\<PATH TO MY bash.exe>",
            ],
            "args": [],
            "icon": "terminal-bash"
          }
      },
    "terminal.integrated.defaultProfile.windows": "Command Prompt",
    

    【讨论】:

      【解决方案4】:

      我在使用 VS Code v1.60.1 时遇到了同样的问题,所以我将其降级到 v1.59.1 (https://code.visualstudio.com/updates/v1_59) 工作正常,并且还禁用了自动更新

      【讨论】:

      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center。
      猜你喜欢
      • 2013-11-04
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      • 1970-01-01
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多