VSCode: 打开新终端作为任务的一部分?
VSCode: Open new terminal as part of task?
Visual Studio 刚刚更新了代码以允许 运行 执行任务并在拆分终端中打开它们。这很棒,但是我正在寻找另一件事来使它变得完美。
我希望能够通过一个任务总共打开 3 个终端。一个用于我的 NPM 构建,一个用于我的后端 MAVEN 构建,第三个只是一个空白的新终端,我可以在需要时用于 git 命令。
我似乎无法找到一种方法来告诉 VSC 运行 一项任务,该任务仅打开一个新终端即可使用,而无需向其提供命令。我什至愿意给它一个简单的命令,比如 "node -v" 来启动它,只要该面板之后仍然可用。现在它想在 运行.
之后关闭它
这是我的任务设置:我将一个任务设置为依赖于其他两个的构建任务。我设想将第三个添加到只会打开新终端的终端:
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Maven and NPM",
"dependsOn": [ "maven", "npm" ],
"group": {
"kind": "build",
"isDefault": true,
},
},
{
"label": "maven",
"command": "...",
"type": "shell",
"presentation": {
"reveal": "always",
"group": "build"
},
"options": {
"cwd": "${workspaceRoot}/server"
}
},
{
"label": "npm",
"type": "shell",
"command": "ng serve --port 4203 --proxy-config proxy.conf.json",
"presentation": {
"reveal": "always",
"group": "build"
},
"options": {
"cwd": "${workspaceRoot}/client-APS"
}
}
]
}
以下应该有效:
{
"type": "process",
"label": "terminal",
"command": "/bin/bash", // <-- your shell here
"args": [
"-l" // login shell for bash
],
"problemMatcher": [],
"presentation": {
"echo": false, // silence "Executing task ..."
"focus": true,
"group": "build", // some arbitrary name for the group
"panel": "dedicated"
},
"runOptions": {
"runOn": "folderOpen"
}
}
当我偶然发现这个解决方案时,我试图实现非常相似的东西:在这里,当在 vscode 中打开文件夹时,我将自动启动(并将焦点设置在)终端-- 共享相同 presentation.group
的其他任务在 运行 时被放置在拆分终端中(新拆分与重用拆分取决于它们的 presentation.panel
)
(运行Options 位对你的情况来说是多余的,但我保留它以防它对某人有帮助)
注意:对于此示例,您可能需要也可能不需要 -l
选项,具体取决于您对 terminal.integrated.shell*
、terminal.integrated.automationShell*
和 terminal.integrated.inheritEnv
的设置 -- this 问题讨论了设置 shell 环境所涉及的内容。
Visual Studio 刚刚更新了代码以允许 运行 执行任务并在拆分终端中打开它们。这很棒,但是我正在寻找另一件事来使它变得完美。
我希望能够通过一个任务总共打开 3 个终端。一个用于我的 NPM 构建,一个用于我的后端 MAVEN 构建,第三个只是一个空白的新终端,我可以在需要时用于 git 命令。
我似乎无法找到一种方法来告诉 VSC 运行 一项任务,该任务仅打开一个新终端即可使用,而无需向其提供命令。我什至愿意给它一个简单的命令,比如 "node -v" 来启动它,只要该面板之后仍然可用。现在它想在 运行.
之后关闭它这是我的任务设置:我将一个任务设置为依赖于其他两个的构建任务。我设想将第三个添加到只会打开新终端的终端:
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Maven and NPM",
"dependsOn": [ "maven", "npm" ],
"group": {
"kind": "build",
"isDefault": true,
},
},
{
"label": "maven",
"command": "...",
"type": "shell",
"presentation": {
"reveal": "always",
"group": "build"
},
"options": {
"cwd": "${workspaceRoot}/server"
}
},
{
"label": "npm",
"type": "shell",
"command": "ng serve --port 4203 --proxy-config proxy.conf.json",
"presentation": {
"reveal": "always",
"group": "build"
},
"options": {
"cwd": "${workspaceRoot}/client-APS"
}
}
]
}
以下应该有效:
{
"type": "process",
"label": "terminal",
"command": "/bin/bash", // <-- your shell here
"args": [
"-l" // login shell for bash
],
"problemMatcher": [],
"presentation": {
"echo": false, // silence "Executing task ..."
"focus": true,
"group": "build", // some arbitrary name for the group
"panel": "dedicated"
},
"runOptions": {
"runOn": "folderOpen"
}
}
当我偶然发现这个解决方案时,我试图实现非常相似的东西:在这里,当在 vscode 中打开文件夹时,我将自动启动(并将焦点设置在)终端-- 共享相同 presentation.group
的其他任务在 运行 时被放置在拆分终端中(新拆分与重用拆分取决于它们的 presentation.panel
)
(运行Options 位对你的情况来说是多余的,但我保留它以防它对某人有帮助)
注意:对于此示例,您可能需要也可能不需要 -l
选项,具体取决于您对 terminal.integrated.shell*
、terminal.integrated.automationShell*
和 terminal.integrated.inheritEnv
的设置 -- this 问题讨论了设置 shell 环境所涉及的内容。