Reputation: 2784
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"]
}
},
{
"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"
}
},
]
}
Upvotes: 20
Views: 20811
Reputation: 4217
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
Upvotes: 0
Reputation: 898
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"
Upvotes: 32
Reputation: 3201
via GUI you can do the following
Press command
+ ,
and search for terminal.integrated.showExitAlert
than unselect thick like below >
I hope that will not get minus points here...
Upvotes: 3
Reputation: 2118
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"
}
Upvotes: 6
Reputation: 308
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
Upvotes: 5
Reputation: 3069
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 PATH
s 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...
Upvotes: 2