kyo*_*kyo 4 macos visual-studio-code vscode-settings vscode-tasks
我在 Mac 上。我正在尝试探索一种创建 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": {}
}
Run Code Online (Sandbox Code Playgroud)
我的目标是开4个航站楼
我一直在关注这个文档:https : //code.visualstudio.com/docs/editor/integrated-terminal#_terminal-keybindings
对我有什么提示吗?
The*_*Pea 18
我喜欢接受的答案。但是,我不想使用已multi-command接受答案中所示的扩展,我认为我的方法更简单。
请注意我的情况:
craft-server和craft-app)craft-site——但是这种方法应该适用于三个以上的任务请参阅下面我的tasks.json文件。您需要修改"label"和"command"属性以适合您的项目。请参阅下面我对重要部分的注释。
{
"version": "2.0.0",
"tasks": [
/// ...other tasks...
{
"label": "runDevelopment",
"runOptions": {
"runOn": "folderOpen"
},
"dependsOrder": "parallel",
"dependsOn": [
"craft-server",
"craft-site",
"craft-app"
]
},
{
"label": "craft-server",
"type": "shell",
"command": "npx nodemon --watch . --ignore craft-angular/projects/craft-app/ --ignore craft-angular/projects/craft-site/ --ignore dist/ --ignore bin/ --ignore log/ --ignore cypress/ --ignore cypress.json ./bin/www",
"presentation": {
"panel": "dedicated"
}
},
{
"label": "craft-site",
"type": "shell",
"command": "cd ./craft-angular && node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng build craft-site --verbose=false --progress=true --watch --output-path=\"./dist/development/craft-site\"",
"presentation": {
"panel": "dedicated"
}
},
{
"label": "craft-app",
"type": "shell",
"command": "cd ./craft-angular && node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng build craft-app --verbose=false --progress=true --watch --output-path=\"./dist/development/craft-app\"",
"presentation": {
"panel": "dedicated"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
请注意:
tasks.json/自定义任务功能(我不使用 VS Code 扩展)"dependsOn"接受的答案中所示的方法,以便一个任务可以并行调用多个其他任务(注意"dependsOrder": "parallel")"runOptions": {"runOn": "folderOpen"}接受的答案中所示的方法,以便当我打开工作区/项目时 VSCode 会自动运行我的“组合”任务
"problemMatcher"属性(即 VS Code 功能来扫描每个终端的输出);因此,当我运行任务时,我选择“继续而不扫描任务输出”"presentation"属性,{"panel":"dedicated"}因此我的每个任务都有一个单独的终端(也称为单独的面板)当我打开工作区/项目/文件夹(即包含文件夹和文件的位置,使用( ) 或)时,任务runDevelopment应该自动运行.vscode.vscode/tasks.jsonFile > Open Folder...Ctrl+K Ctrl+OFile > Open Recent...
虽然我希望此任务自动运行,但下面显示了如何手动运行该任务(如果需要,例如自动任务失败,或者我终止自动任务);
您可以用来Ctrl+Shift+B运行构建任务,如 @Ruben 所评论的,以及此处 VSCode 键盘绑定中的描述。
或者您可以使用更分步的方法:
runDevelopment; hit Enter)"problemMatcher",我可以自己解释任务输出):

这是任务运行后的样子;请注意,有 3 个单独的终端用于 3 个单独的子任务:

我一直在玩这个似乎有效的方法。结合在文件夹打开时运行任务并使该任务依赖于其他任务的能力,我想出了以下内容。它看起来很麻烦,但实际上非常简单和重复。
首先,您将需要一个宏扩展,如multi-command。将其放入您的设置中:
"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"
]
}
]
Run Code Online (Sandbox Code Playgroud)
每个终端有一个命令。但是在每一个中,你可以做尽可能多的宏 - 这是很多,特别是感谢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}"
}
]
Run Code Online (Sandbox Code Playgroud)
现在,无论何时打开(或重新加载)工作区文件夹,都应该打开、命名和运行四个终端中的 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"
},
Run Code Online (Sandbox Code Playgroud)
这里有一个使用keybinding运行的demo,比重装vscode更容易演示,但是没有区别。我为每个运行的终端添加了一个间隔延迟,只是为了演示目的——否则它会非常快。
我注意到如果在删除所有终端之前我不与其中一个终端交互或打开另一个终端,vscode 会冻结。
还有一个可能感兴趣的终端管理器扩展。我没试过。
一次设置多个终端的扩展,或者只是运行一些命令。
但是我不清楚这个扩展是否可以配置为在 folderOpen 上运行 - 但它似乎提供了一个run all the terminals命令,所以你应该能够在任务中使用它。
| 归档时间: |
|
| 查看次数: |
1567 次 |
| 最近记录: |