What I want to achieve is using zsh in "output" pane whenever I run a Task in VSCode, but it keep using /bin/sh instead.
The "Terminal" pane is using zsh correctly though.
Here's my configurations:
➜ ~ echo $SHELL
/bin/zsh
➜ ~ which zsh
/bin/zsh
tasks.json
{
"version": "0.1.0",
"command": "echo Im $0",
"suppressTaskName": true,
"isShellCommand": {
"executable": "/bin/zsh"
},
"showOutput": "always",
"tasks": [
{
"taskName": "Test",
"args": ["test"]
}
]
}
And the output when I run the Task is:
Im /bin/sh
You could change the settings from menu File -> Preferences -> Settings. Then put the options to use zsh shell.
... another lines
... another lines
"terminal.integrated.shell.linux": "zsh"
The recommended way to do this now is the following:
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "zsh",
"args": []
}
},
"terminal.integrated.defaultProfile.linux": "zsh"
As the other answer presents the deprecated way to do it.
Note that you can customize this profile with arguments if need be :)
Related
My aim is to open zsh terminals in the current working directory of wsl whenever I open a workspace. For example, if I open a workspace with three folders, viz. test1, test2, and test3, I want one terminal in each directory to open in vs code.
For that purpose, I created .vscode/tasks.json file in each directory and input the following code:
{
"version": "2.0.0",
"tasks": [
{
"label": "test1",
"type": "shell",
"command": "",
"isBackground": true,
"problemMatcher": [],
"options": {
"shell": {
"executable": "zsh",
"args": []
}
},
"runOptions": {
"runOn": "folderOpen"
},
"presentation": {
"reveal": "always",
"panel": "dedicated"
}
}
]
}
But in the terminal, I get this error:
* Executing task in folder illuminate:
/usr/bin/zsh: can't open input file:
* The terminal process "zsh ''" failed to launch (exit code: 127).
* Terminal will be reused by tasks, press any key to close it.
I checked the docs, but it includes settings only useful for windows, not linux. Is there any way to achieve this?
I have had a setup for a while to run C++ programs in VS Code. It was basically a tasks.json which looked like this
"tasks": [
{
"label": "Compile and run",
"type": "shell",
"command": "",
"args": [
"g++",
"${fileBasename}",
"-o",
"test",
"&&",
...
}
I had also kept a settings.json to define the terminal to be used which was command Prompt,
For some reason in the latest update for VS Code my setup got messed and it does not work anymore.
I would like to know the right syntax to define cmd as the terminal for running the tasks since things like && < > dont work in powershell
After Luuk's comment I did more digging and found the followig to work for my vs code tasks problem. I only had to change && to ; and for the input out redirection I used this answer. Now my tasks.json looks like this
"tasks": [
{
"label": "Compile and run",
"type": "shell",
"command": "",
"args": [
"g++",
"${fileBasename}",
"-o",
"test",
";",
"cmd",
"/c",
"'test.exe < input.txt > output.txt'",
";",
"del",
"*exe",
";",
"del",
"${fileBasename}"
}
]
I am trying to define a VSCode task in tasks.json that would adapt to the specific architecture where VSCode runs. To do this, I want to get the architecture as uname --m (e.g. "aarch64" or "amd64"). My goal is to interpolate the output of uname into an environment variable like so
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "cmake",
"args": [
"-DMYLIB_INCLUDE_DIR=$MYLIB/include",
"-DMYLIB_LIBRARY=$MYLIB/lib"
],
"options": {
"env": {
"MYLIB": "${workspaceFolder}/mylib/${command:get_arch}"
}
},
}
]
In my case, I will have architecture-specific versions of mylib under mylib/aarch64, mylib/amd64, etc.
My attempt so far as been to define a second get_arch task used in the environment definition of MYLIB, that simply runs uname.
{
"label": "get_arch",
"type": "shell",
"command": "uname --m"
}
Of course, this task is not a proper command and so it isn't detected by VSCode and my build task fails. I checked out the documentation on variable substition, but they don't mention if it's possible to substitute a shell command. I guess this would be possible from within an extension, but I want to keep things as simple as possible.
This extension provides a way to launch arbitrary shell commands as a VS Code command:
"tasks": [
{
"label": "test_arch",
"type": "shell",
"command": "echo",
"args": [
"${MYARCH}"
],
"options": {
"env": {
"MYARCH": "${input:get_arch}"
}
},
"problemMatcher": []
},
],
"inputs": [
{
"id": "get_arch",
"type": "command",
"command": "shellCommand.execute",
"args": {
"command": "uname -m"
}
}
]
One disadvantage I discovered is that you have to press Enter once more when the result of the command is prompted in picker. Aside of this, this is the straightest way to implement what you want, and yet it can be utilized in many similar situations.
Alternatively, you can add pickString input with arch picker or create an extension that adds only single command GetArch.
If you don't want to press enter every time, you can add the option useFirstResult: true in the args section.
I would like to build my program using Git Bash or MinGW so I have this build task:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "gcc",
"args": ["-g", "${relativeFile}", "-o", "${fileBasenameNoExtension}"],
"options": {
"shell": {
"executable": "C:\\Program Files\\Git\\bin\\bash.exe",
"args": ["-l"]
},
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
},
]
}
I have two issues:
The cwd command does not work because ${fileDirname} is in the Windows form C:\Foo\Bar and since I am on bash I would like the POSIX form /c/Foo/Bar.
My task is not executed in the current terminal, but in a weird Window that display no output:
/usr/bin/bash: gcc -g .vscode\tasks.json -o tasks: No such file or directory
The terminal process terminated with exit code: 127
Terminal will be reused by tasks, press any key to close it.
With the extension Command Variable (v0.2.0) you can add Posix versions of the directory variables.
"cwd": "${command:extension.commandvariable.file.fileDirnamePosix}"
I would like to run a background service like MongoDB from Visual Studio Code. I tried to run it through the task runner like this:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "mongod",
"isShellCommand": false,
"args": ["--dbpath", "data\\db"],
"showOutput": "always"
}
But this will only run it inside VS with no control to stop the server, e.g. by pressing Ctrl+C.
The normal way would be to run a cmd.exe and run the mongod command from there. But I would love to nicely integrate it into VS.
Found a solution to the problem by using one command with subtasks.
This will run "mongod" in a separate cmd.exe shell.
Once started (in this case minimized via /MIN), I can stop the MongoDB by opening the cmd windows and pressing ctrl+C to properly shutdown the database.
It would still be nicer to have the shell running inside vscode, but maybe this will come in an update someday.
{
"version": "0.1.0",
"command": "start",
"isShellCommand": true,
"showOutput": "never",
"args": [
"/MIN"
],
"tasks": [
{
"taskName": "Start MongoDB",
"args": [
"\"MongoDB # localhost:27017\"",
"mongod",
"--dbpath",
"${workspaceRoot}/data/db"
],
"suppressTaskName": true
}
]
}
You can define a watching task like in this webpack example:
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"echoCommand": false,
"suppressTaskName": true,
"showOutput": "always",
"tasks": [
{
"args": [
"run",
"start",
"--silent"
],
"problemMatcher": [
{
"owner": "custom",
"pattern": [],
"watching": {
"activeOnStart": true,
"beginsPattern": "webpack: bundle is now INVALID",
"endsPattern": "webpack: bundle is now VALID"
}
}
],
"isWatching": true,
"taskName": "development"
}
]
}
The (optional) problem Matcher watching beginsPattern and endsPattern define the console output of the watcher task start and end. The watching task can be terminated via command palette.
https://github.com/Microsoft/vscode/issues/6209#issuecomment-218154235