我可以通过 CLI 在 VS Code 中打开一个文件夹,并在集成终端上运行一个命令吗?

编程入门 行业动态 更新时间:2024-10-28 04:17:50
本文介绍了我可以通过 CLI 在 VS Code 中打开一个文件夹,并在集成终端上运行一个命令吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

当我从我的本机终端打开一个文件夹时,使用 code ./workspace 我想添加参数来告诉它应该在 VS 内的集成终端上直接运行特定命令代码本身.

code ./workspace/--npm buildcode ./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:关键词]

本文发布于:2023-05-01 00:12:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1401817.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并在   可以通过   终端   文件夹   命令

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!