我在苹果电脑上。我试图探索一种方法来创建4个终端,只要我的dbl-点击我的工作空间文件。我试过找一份工作,但我好像被困住了
{
"folders": [
{
"path": "/Users/bheng/Sites/laravel/project"
}
],
"settings": {
"workbench.action.terminal.focus": true,
"terminal.integrated.shell.osx": "ls",
"terminal.integrated.shellArgs.osx": [
"ls -lrt"
]
},
"extensions": {}
}
我的目标是开四个终点站
我一直在跟踪这个医生:终端键绑定
有什么提示吗?
发布于 2020-03-13 05:57:59
我一直在玩这个好像挺管用的。将在文件夹上运行任务的能力结合起来,并使该任务依赖于其他任务,我想出了以下内容。它看起来很麻烦,但实际上很简单,而且是重复的。
首先,您需要像多命令这样的宏扩展。把这个放到你的设置中:
"multiCommand.commands": [
{
"command": "multiCommand.runInFirstTerminal",
"sequence": [
"workbench.action.terminal.new",
{
"command": "workbench.action.terminal.renameWithArg",
"args": {
"name": "npm watch"
}
},
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "npm run watch\u000D" // \u000D is a return so it runs
}
}
]
},
{
"command": "multiCommand.runInSecondTerminal",
"sequence": [
"workbench.action.terminal.new",
{
"command": "workbench.action.terminal.renameWithArg",
"args": {
"name": "ls -lrt"
}
},
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "ls -lrt\u000D"
}
}
]
},
{
"command": "multiCommand.runInThirdTerminal",
"sequence": [
"workbench.action.terminal.new",
{
"command": "workbench.action.terminal.renameWithArg",
"args": {
"name": "ssh_staging"
}
},
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "ssh_staging\u000D" // however you run the ssh_staging command
}
}
]
},
{
"command": "multiCommand.runInFourthTerminal",
"sequence": [
"workbench.action.terminal.new",
{
"command": "workbench.action.terminal.renameWithArg",
"args": {
"name": "mysql"
}
},
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "mysql\u000D" // however you run the mysql command
}
},
// "workbench.action.focusActiveEditorGroup"
]
}
]
每个终端都有一个命令。但是在每个宏中,您可以尽可能多地进入宏--这非常多,特别是由于有了sendSequence
命令。您可以更改目录并向同一个终端实例发送另一个sendSequence
命令,也可以运行所有非终端命令,在最后一个终端设置结束时将焦点更改为编辑器,等等。
我添加了使用命令workbench.action.terminal.renameWithArg
根据命令命名每个终端的精确性。
在tasks.json中:
"tasks": [
{
"label": "Run 4 terminals on startup",
"runOptions": {"runOn": "folderOpen"},
"dependsOrder": "sequence", // or parallel
"dependsOn": [
"terminal1",
"terminal2",
"terminal3",
"terminal4"
]
},
{
"label": "terminal1",
"command": "${command:multiCommand.runInFirstTerminal}"
},
{
"label": "terminal2",
"command": "${command:multiCommand.runInSecondTerminal}",
},
{
"label": "terminal3",
"command": "${command:multiCommand.runInThirdTerminal}"
},
{
"label": "terminal4",
"command": "${command:multiCommand.runInFourthTerminal}"
}
]
现在,无论何时打开(或重新加载)工作区文件夹,都应该打开、命名和运行四个终端中的tasks.json。根据我的经验,在vscode运行任何folderOpen任务之前有一个很短的延迟。
如果您希望手动触发Run 4 terminals
任务,则可以设置如下所示的密钥绑定:
{
"key": "alt+r", // whatever keybinding you want
"command": "workbench.action.tasks.runTask",
"args": "Run 4 terminals on startup"
},
下面是一个使用键绑定运行的演示,它比重新加载vscode更容易演示,但是没有区别。为了演示目的,我给每一个运行的终端增加了一个间隔延迟--否则它会非常快。
我注意到,如果我不与其中一个终端交互,或者在删除所有终端之前打开另一个终端,vscode就会冻结。
还有一个可能感兴趣的终端管理器扩展。我还没试过。
一种扩展,用于同时设置多个终端,或只运行一些命令.
但对于我来说,这个扩展是否可以配置为在folderOpen上运行并不明显--但它似乎贡献了一个run all the terminals
命令,因此您应该能够在任务中使用它。
发布于 2021-12-17 04:46:08
我喜欢只使用vscode任务的第二个答案,但它不适合我的要求,因为我不能在开放终端中输入其他指令,否则它会关闭。我更喜欢在vscode中使用恢复终端。
安装扩展名后,只需在restore-terminals.json
文件夹中创建一个.vscode
文件:
{
"artificialDelayMilliseconds": 300,
"keepExistingTerminalsOpen": false,
"runOnStartup": true,
"terminals": [
{
"splitTerminals": [
{
"name": "server",
"commands": ["npm i", "npm run dev"]
},
{
"name": "client",
"commands": ["npm run dev:client"]
},
{
"name": "test",
"commands": ["jest --watch"]
}
]
},
{
"splitTerminals": [
{
"name": "build & e2e",
"commands": ["npm run eslint", "npm run build", "npm run e2e"],
"shouldRunCommands": false
},
{
"name": "worker",
"commands": ["npm-run-all --parallel redis tsc-watch-start worker"]
}
]
}
]
}
https://stackoverflow.com/questions/60621321
复制相似问题