问题描述
限时送ChatGPT账号..当我从我的本机终端打开一个文件夹时,使用 code ./workspace
我想添加参数来告诉它应该在 VS 内的集成终端上直接运行特定命令代码本身.
像 code ./workspace/--npm build
或 code ./workspace/&&代码 windowindex=0 --t --npm build
?
VS Code CLI 不支持此 AFAIK.
我目前的解决方法是使用 code
正常打开工作区,然后使用在 VS Code 启动时触发的扩展(当窗口打开时)来创建我的终端并在它们上运行命令.>
有几个这样的扩展,但我个人使用
在 terminals.json 文件中定义您的终端(请参阅
我更喜欢这个,即使有一个 code --option
来做到这一点,因为如果我手动"打开 VS Code(即通过从 Dock 中单击它的图标),它也会做同样的事情.我不需要单独的配置/设置.
When I open a folder from my native terminal, with code ./workspace
I'd like to add parameters to tell that it should straight-up run a specific command on an integrated terminal inside VS Code itself.
Like code ./workspace/ --npm build
or code ./workspace/ && code windowindex=0 --t --npm build
?
The VS Code CLI does not support this AFAIK.
My current workaround is to use code
to open a workspace normally, then use extensions that trigger on VS Code startup (when the window opens) to create my terminals and runs commands on them.
There are a couple of these extensions, but personally I use Terminals Manager.
Create and save a workspace (ex. myapp.code-workspace)
On your workspace, create a .vscode/terminals.json file
Define your terminals in the terminals.json file (refer to the extension's page for the syntax). For example, let's say I want to have 1 terminal that will auto-run npm run start
and 1 terminal that does git fetch
:
{
"autorun": true,
"terminals": [
{
"name": "NPM",
"description": "For NPM commands",
"focus": true,
"commands": [
"cd myapp",
"npm run start"
]
},
{
"name": "GIT",
"description": "For GIT commands",
"focus": false,
"command": "git fetch -v"
}
]
}
When you now do code myapp.code-workspace
, that should open VS Code and open the defined terminals (with the focus on the terminal with focus: true
) and run the listed commands:
I like this better even if there's a code --option
to do this, because if I open VS Code "manually" (i.e. by clicking its icon from the dock), then it will also do the same thing. I won't need a separate config/setup.
这篇关于我可以通过 CLI 在 VS Code 中打开一个文件夹,并在集成终端上运行一个命令吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论