【问题标题】:VSCode terminal task not using zsh profileVSCode 终端任务不使用 zsh 配置文件
【发布时间】:2022-05-18 03:07:32
【问题描述】:

我正在尝试在 VSCode 中运行一个窗口加载任务,其中终端打开,nvm use && yarn dev 默认运行。但是,运行这个 shell 任务似乎没有加载我的 zsh 配置文件。

我运行任务得到的输出是:

The terminal process "zsh '-c', 'nvm use && yarn dev'" terminated with exit code: 127.

Terminal will be reused by tasks, press any key to close it.

但是,如果我随后手动启动一个新终端并运行相同的命令(即:按加号,打开一个新的集成终端),它将按预期工作。

怀疑 VSCode 出于某种原因没有加载我的个人资料,我尝试将以下内容添加到我的任务中,导致错误 /bin/zsh: can't open input file: nvm use && yarn dev The terminal process "zsh '-l', 'nvm use && yarn dev'" terminated with exit code: 127.

// in dev task
"options": {
  "shell": {
    "executable": "zsh",
    "args": ["-l"]
  }
},

.vscode/tasks.json

{
    "version": "2.0.0",
    "presentation": {
      "echo": false,
      "reveal": "always",
      "focus": false,
      "panel": "dedicated",
      "showReuseMessage": true
    },
    "tasks": [
      {
        "label": "Create terminals",
        "dependsOn": [
          "Dev",
        ],
        // Mark as the default build task so cmd/ctrl+shift+b will create them
        "group": {
          "kind": "build",
          "isDefault": true
        },
        // Try start the task on folder open
        "runOptions": {
          "runOn": "folderOpen"
        }
      },
      {
        "label": "Dev",
        "type": "shell",
        "command": 
          ["nvm use && yarn dev"],
        "isBackground": true,
        "problemMatcher": [],
        "presentation": {
          "group": "dev-group"
        }
      },
    ]
  }

【问题讨论】:

标签: visual-studio-code zsh nvm


【解决方案1】:

这对我有用-

"terminal.integrated.profiles.osx": {
    "zsh": {
        "path": "/bin/zsh",
        "args": ["-l", "-i"]
    }
},

github.com/microsoft/vscode/issues/143061

【讨论】:

    【解决方案2】:

    尝试将此添加到您的settings.json

      "terminal.integrated.profiles.osx": {
            [...]
            "zsh": {
                "path": "/bin/zsh -l",
                "args": [
                    "-l"
                ]
            },
            [...]
      },
    

    注意重要的部分是

        "path": "/bin/zsh -l",
    

    我遇到了同样的问题,我发现出于某种原因 VScode 没有考虑到 args 中传递的 -l 标志。因此,您可以将其包含在 path 中。

    如果您的设置中没有terminal.integrated.profiles.osx,您可以从默认设置中复制它(打开命令面板并搜索“默认设置”)。

    我不需要这样做,但是您可以通过将 terminal.integrated.defaultProfile.osx 设置为 zsh 来确保 zsh 是 VScode 的默认终端配置文件

    【讨论】:

    • 我的集成终端正常工作,不幸的是这对问题没有帮助。
    【解决方案3】:

    尝试从 VSCode 的集成终端运行 echo $SHELL。如果您使用的是 Mac 或 Linux 机器,则可以将该输出与终端应用程序的输出(在 VSCode 之外)进行比较。可能是您在 VSCode 中的默认 shell 设置不正确,或者在其他位置使用了 zsh 的副本。如果是这样,请通过命令面板(Terminal: Select Default Shell)设置 VSCode 的默认 shell。

    还可以从命令面板中检查您的 shell 的默认配置文件 (Terminal: Select Default Profile) 并确保将其设置为 zsh -l... 使用 -c 参数(非登录非交互式)将阻止 ~/.zshrc从被执行,这听起来像这里发生了什么给你的错误输出。

    最后,确认您的配置文件位置正确(~/.zshrc),并且 nvm 和 yarn PATHs 都已导出。或者,如果您尝试在本地引用 yarn(如果由于某种原因只在本地安装),则需要通过 npx 运行 yarn...

    【讨论】:

    • 我的默认 shell 工作正常(通过集成终端)。唯一的问题是当我尝试从 VSCode 任务自动运行 shell 时。
    【解决方案4】:

    您可能还需要添加自动化配置文件

      "terminal.integrated.profiles.osx": {
        "zsh": {
          "path": "/bin/zsh -l",
          "args": ["-l"]
        }
      },
      "terminal.integrated.automationProfile.osx": {
        "path": "/bin/zsh"
      }
    

    【讨论】:

      猜你喜欢
      • 2023-01-12
      • 2022-01-10
      • 1970-01-01
      • 2017-06-21
      • 1970-01-01
      • 2018-09-02
      • 1970-01-01
      • 1970-01-01
      • 2019-11-18
      相关资源
      最近更新 更多