VSCode terminal task not using zsh profile
Asked Answered
C

6

19

I'm trying to run a task on window load in VSCode where a terminal opens and nvm use && yarn dev is run by default. However, running this shell tasks seems to not load my zsh profile.

The output I get from running my task is:

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.

But if I then manually start a new terminal and run the same command (ie: by pressing plus, opening a new integrated terminal), it will work as intended.

Suspecting that VSCode isn't loading my profile for some reason, I tried adding the following to my task, it resulted in the error /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"
        }
      },
    ]
  }
Curiel answered 24/1, 2022 at 16:21 Comment(1)
I am also having the same problem and none of the answers resolve this. Opened a bug for this github.com/microsoft/vscode/issues/143061Acheron
A
31

This worked for me*:

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

*(add to your settings.json)

github.com/microsoft/vscode/issues/143061

Update- For default shell provide the below setting-

"terminal.integrated.defaultProfile.osx": "zsh"
Acheron answered 17/2, 2022 at 10:56 Comment(2)
It doesn't work for me. Although "args": ["-l", "-i"] is set, what is actually executed is /bin/zsh '-l', '-i', '-c'。According to Tim's answer below, -c means not to start the shell as non-login, non-interactive, so the ~/.zshrc configuration cannot be loaded.Headrest
works for me in mac - 31/may/2024Gaylagayle
R
6

You may need to add an automation profile as well

  "terminal.integrated.profiles.osx": {
    "zsh": {
      "path": "/bin/zsh -l",
      "args": ["-l"]
    }
  },
  "terminal.integrated.automationProfile.osx": {
    "path": "/bin/zsh"
  }
Rigid answered 17/5, 2022 at 19:7 Comment(0)
A
5

try adding this to your settings.json

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

Note that the important part is

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

I had the same problem and I found that for some reason VScode does not take into consideration the -l flag passed in args. So you can just include it with path.

If you do not have terminal.integrated.profiles.osx in your settings, you can copy it from the default settings (open the Command Palette and search for 'default settings').

I did not need to do this, but you can make sure that zsh is the default terminal profile for VScode by setting terminal.integrated.defaultProfile.osx to zsh

Appointee answered 1/2, 2022 at 15:12 Comment(1)
My integrated terminal works fine normally, and this did not help the issue unfortunately.Curiel
A
3

via GUI you can do the following

Press command + , and search for terminal.integrated.showExitAlert than unselect thick like below > enter image description here

I hope that will not get minus points here...

Apospory answered 13/12, 2022 at 15:31 Comment(0)
L
2

Try running echo $SHELL from VSCode's integrated terminal. If you're on a Mac or Linux machine, you can compare that output to the output from the terminal app (outside VSCode). It's possible your default shell in VSCode is set incorrectly or using a copy of zsh at another location. If so, set VSCode's default shell through the command palette (Terminal: Select Default Shell).

Also check out your shell's default profile (Terminal: Select Default Profile) from the command palette and make sure it's set to zsh -l... using the -c argument (non-login non-interactive) will prevent ~/.zshrc from being executed, which sounds like what's going on here given your error output.

Finally, confirm your profile is located correctly (at ~/.zshrc) and that both nvm and yarn PATHs are exported. Alternatively, if you're trying to reference yarn locally (if for some reason you only installed it locally), you'll need to run yarn via npx...

Languet answered 30/1, 2022 at 19:25 Comment(2)
My default shell works fine (via the integrated terminal). The only issue is when I'm trying to run the shell automatically from a VSCode task.Curiel
Although "args": ["-l", "-i"] is set, what is actually executed is /bin/zsh '-l', '-i', '-c'. Do you know why?Headrest
F
0

open ~/.config/Code/User/settings.json

add your default shell depending on you OS:

"terminal.integrated.defaultProfile.linux": "zsh"
"terminal.integrated.defaultProfile.osx": "zsh"
"terminal.integrated.defaultProfile.windows": "zsh"

credit: ZSH And VSCode - Default Shells

Foraminifer answered 2/8 at 10:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.