Is there a way to open terminal by default in VSCode? I saw the questions here four years ago - VS Code - How to have Terminal pane open by default? not sure if there is any update.
You can use the tasks.json file to "auto-run" terminals with Tasks. See documentation at https://code.visualstudio.com/docs/editor/integrated-terminal#_automating-launching-of-terminals
tasks.json template:
{
"version": "2.0.0",
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": true
},
"tasks": [
{
"label": "Open terminal by default",
"dependsOn": [
"Terminal"
],
"runOptions": {
"runOn": "folderOpen"
}
},
{
// The name that shows up in terminal tab
"label": "PowerShell",
// The task will launch a shell
"type": "shell",
"command": "",
// Set the shell type
"options": {
"shell": {
"executable": "powershell.exe",
"args": []
}
},
// Mark as a background task to avoid the spinner animation on the terminal tab
"isBackground": true,
"problemMatcher": []
}
]
}
Related
I'm working with VSCode Tasks and my goal is to simply open a set of integrated WSL terminals and navigate each to a specified directory when the workspace launches.
I'm using the workspace's tasks object and currently can launch WSL terminals, but can't seem to specify the directory.
Below is my current configuration. It launches my wsl terminals no problem, but with cwd does not correctly map. When using cmd.exe instead of wsl, it works fine.
"tasks": {
"version": "2.0.0",
"tasks": [
//Worker Task to Open Each Terminal.
{
"label": "Create terminals",
"dependsOn": [
"WSL_Terminal_1",
"WSL_Terminal_2",...
],
"group": {
"kind": "build",
"isDefault": true
},
//Run When Workspace Opens.
"runOptions": {
"runOn": "folderOpen"
}
},
//Single Terminal Task.
{
"label": "WSL_Terminal_1",
"type": "shell",
"command": "",
"options": {
"cwd":"/mnt/c/my/working/dir",
"shell": {
"executable": "C:\\...\\ubuntu2004.exe",
}
},
"icon": {"color": "terminal.ansiMagenta", "id": "terminal-linux" },
"isBackground": true,
"problemMatcher": [],
"presentation": {
"echo": false,
"focus": false,
"reveal": "always",
"panel": "new",
}
},
...
I've tried some combination of args with no success
//tested 1
"shell": {
"executable": "C:\\...\\ubuntu2004.exe",
"args": ["-c 'cd /mnt/c/my/working/dir'"],
}
//tested 2
"shell": {
"executable": "C:\\...\\ubuntu2004.exe",
"args": ["-c",
"cd /mnt/c/my/working/dir"
],
}
I tried several versions of cwd as well with no positive results
//Throws Error on running task
"cwd":"/mnt/c/my/working/dir"
//No error but WSL terminal still opens at /home/user
"cwd":"C:\\my\\working\\dir"
//Linux Side Paths also not working
"cwd":"/home/user/test_dir"
"cwd":"test_dir"
I have this task I've created:
{
"label": "Regen Coverage",
"type": "shell",
"group": "test",
"presentation": {
"reveal": "always",
"panel": "dedicated"
},
"command": [
"go test ./internal/... --tags=dynamic,integration -coverpkg=./... -count=1 -coverprofile ./cover.out",
"gcov2lcov -infile=cover.out -outfile=cover.lcov",
]
}
I'd like to trigger a command palette action from an extension (the command is Coverage Gutters: Watch. I think this should be possible, based on this ticket: https://github.com/microsoft/vscode/issues/11396, but I have no idea what the command would be called, and the docs say that a command must return a string. Any ideas?
Thank you to #rioV8 I was able to find the commandID from the key binding GUI. This is the resulting task setup:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "run integration tests and cover",
"type": "shell",
"group": "test",
"presentation": {
"reveal": "always",
"panel": "shared"
},
"command": [
"go test ./internal/... --tags=dynamic,integration -coverpkg=./... -count=1 -coverprofile ./cover.out",
"gcov2lcov -infile=cover.out -outfile=cover.lcov"
]
},
{
"label": "Regen and Watch Coverage",
"dependsOn": [
"run integration tests and cover"
],
"presentation": {
"reveal": "always",
"panel": "shared"
},
"command": [
"${command:coverage-gutters.watchCoverageAndVisibleEditors}"
],
"problemMatcher": []
}
]
}
I have the below tasks.json and it works fine, except that they are run from Powershell. And the browser-sync task gives an error: "browser-sync : File C:\Users\marti\AppData\Roaming\npm\browser-sync.ps1 cannot be loaded because running scripts is disabled on this system."
It works fine if tasks are run from Cmd terminal instead. How can I make them start from there? I have set Cmd as default terminal in VS.
{
"version": "2.0.0",
"tasks": [
{
"label": "Start watching scss and js",
"type": "cmd",
"command": "npm start",
"presentation": {
"reveal": "always",
"panel": "new"
},
"runOptions": { "runOn": "folderOpen" }
},
{
"label": "Start browser-sync",
"type": "shell",
"command": "browser-sync start --proxy \"localhost:5829\" --files \"css/*.css\"",
"presentation": {
"reveal": "always",
"panel": "new"
},
"runOptions": { "runOn": "folderOpen" }
}
]
}
I have this task,
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run Jest on Current File",
"type": "shell",
"command": "yarn",
"options": {
"env": {
"CI": "true"
}
},
"args": ["test", "${file}"],
"problemMatcher": [],
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": false
}
}
]
}
This shows what I mean by second terminal pane
I would like for this to run in the current terminal I have open instead of opening a new one that would close when I press any other button. It would be nice to not have to worry about a different terminal pane specifically for tasks. The task pane doesn't use my color theme, therefore it's harder to see what has passed or failed as well.
My tasks.json looks like this:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
// A task runner that runs a python program
"command": "python3",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true
},
"args": [
"${file}"
]
}
When I run ctrl+shift+B the top panel asks "Select the build task to run", and there's one alternative: python3. Now if I'd like to add a new build-task (for example a runspider command with scrapy), so it's added to the build tasks. How would I go about adding this?
You can define multiple tasks in your tasks.json by assigning an array of task objects to the tasks property, like this:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "python3",
"type": "shell",
"command": "python3",
"args": [
"${file}"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true
}
},
{
"taskName": "runspider",
"type": "shell",
"command": "runspider"
}
]
}
Also, Ctrl+Shift+B runs the default build task, so you might want to set your "workbench.action.tasks.runTask" keybinding.
{
"key": "ctrl+shift+b",
"command": "workbench.action.tasks.runTask"
}
Once that is done, you can select the task when you use workbench.action.tasks.runTask command, as shown below:
You can also choose your default build task by setting the "group" property on the task. Here, in the following snippet, your "python3" task will run as the default build task.
...
"tasks": [
{
"taskName": "python3",
"type": "shell",
"command": "python3",
"args": [
"${file}"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"taskName": "runspider",
"type": "shell",
"command": "runspider"
}
]
...
You can read more about tasks here: Tasks in VSCode