[英]How to open a new tab from inside Visual Studio Code's integrated terminal (not with keyboard shortcuts)?
I want to open a new terminal tab as part of a project I'm working on requires that I run another script in a new tab once I've got the first portion running.作为我正在处理的项目的一部分,我想打开一个新的终端选项卡,这要求我在第一部分运行后在新选项卡中运行另一个脚本。 But I am not seeing how to automate this on macOS Big Sur.
但我没有看到如何在 macOS Big Sur 上自动执行此操作。 I am thinking AppleScript is the way to go, but if there's another way to run from ZSH I'd be thrilled.
我在想 AppleScript 是通往 go 的路,但如果有另一种从 ZSH 运行的方式,我会很高兴。
TLDR; TLDR; I am not aware that it is possible, but all terminal shenanigans for spawning multiple background processes are possible in bash/zsh.
我不知道这是可能的,但是在 bash/zsh 中,所有用于生成多个后台进程的终端恶作剧都是可能的。 See examples below, as well as links.
请参阅下面的示例以及链接。
It isn't possible to create a new terminal inside of Vscode from the terminal itself.无法从终端本身在 Vscode 内部创建新终端。 Same thing goes for Jupyterlab, mainly for security reasons.
Jupyterlab 也是如此,主要是出于安全原因。 But it is possible to spawn another terminal as part of the original command.
但是可以生成另一个终端作为原始命令的一部分。
bash -c 'some string command'
And the use of operators like &
;
以及
&
;
等运算符的使用&&
and ||
&&
和||
, which execute depending on some condition. ,它根据某些条件执行。 Mainly execute and don't wait .
以执行为主,不要等待。 Execute regardless of the first command success
;
不管第一个命令是否成功都执行
;
, and execute if successful and unsuccessful the last two. , 如果最后两个成功和不成功则执行。 ( Check more here)
( 在这里查看更多)
command1 & command2
Example: echo 'something1' & echo 'something2'
produces the following:示例:
echo 'something1' & echo 'something2'
产生以下内容:
[1] 53159
something1
something2
[1] + done echo 'something1'
This can be combined with the first example: bash -c 'sleep 3; echo "something1"' & echo "something2"
这可以与第一个示例结合使用:
bash -c 'sleep 3; echo "something1"' & echo "something2"
bash -c 'sleep 3; echo "something1"' & echo "something2"
which produces: bash -c 'sleep 3; echo "something1"' & echo "something2"
产生:
[1] 60427
something2
<machine_id>% something1
[1] + done bash -c 'sleep 3; echo "something1"'
In addition, you can probably include some waits and signal catching, but that is another can of worms.此外,您可能可以包括一些等待和信号捕获,但那是另一种蠕虫病毒。
I see the VSCode
as a keyword.我将
VSCode
视为关键字。 Not zsh
or Apple
.不是
zsh
或Apple
。
Since it's the main environment you want to work with, you should search for the answers in this environment.既然它是你要工作的主要环境,你应该在这个环境中寻找答案。
And Tasks
feature is the answer: https://code.visualstudio.com/Docs/editor/tasks . Tasks
功能就是答案: https://code.visualstudio.com/Docs/editor/tasks 。 I would highly recommend getting familiar with it.我强烈建议您熟悉它。 It has way more features than I will show in this answer.
它的功能比我将在这个答案中展示的要多得多。
The <task>.presentation.panel
parameter is responsible for specifying a panel (ie tab): "new", "shared", "dedicated". <task>.presentation.panel
参数负责指定一个面板(即选项卡):“new”、“shared”、“dedicated”。
<task>.dependsOn
and <task>.dependsOrder
specify dependencies and orders for them. <task>.dependsOn
和<task>.dependsOrder
指定它们的依赖关系和顺序。
With all these parameters above you may end up with something like that in your tasks.json
:使用上面的所有这些参数,您最终可能会在
tasks.json
中得到类似的东西:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run the first portion",
"type": "shell",
"command": "sleep", // Your program goes here
"args": ["2"], // Your arguments goes here
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new",
"showReuseMessage": true,
"clear": false
},
},
{
"label": "Run the second portion",
"type": "shell",
"command": "echo",
"args": ["Right after the first portion"],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new",
"showReuseMessage": true,
"clear": false
},
},
{
"label": "Run all portions",
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
"Run the first portion",
"Run the second portion",
],
}
]
}
It gives you 3 tasks.它给你3个任务。
Run all portions
is the main one. Run all portions
是主要部分。 But you still will be able to execute others separately.但是你仍然可以单独处决其他人。
Note: tasks will be executed in sequence in different panels/tabs, but it's easy to control.注意:任务将在不同的面板/选项卡中按顺序执行,但很容易控制。 You just need to tune it a bit, if the first portion is not expected to be stopped or executed in a new panel all the time.
如果第一部分不希望一直在新面板中停止或执行,您只需要稍微调整一下。
Note 2: Take a look into the launch.json
if you need an interactive debuggers feature.注意 2:如果您需要交互式调试器功能,请查看
launch.json
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.