我可以通过 CLI 在 VS Code 中打开一个文件夹,并在集成终端上运行一个命令吗? [英] Can I open a folder in VS Code via the CLI WITH a command to be run on the intergrated terminal?

查看:22
本文介绍了我可以通过 CLI 在 VS Code 中打开一个文件夹,并在集成终端上运行一个命令吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从我的本机终端打开一个文件夹时,使用 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.

    1. Create and save a workspace (ex. myapp.code-workspace)

    2. On your workspace, create a .vscode/terminals.json file

    3. 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"
              }
          ]
      }
      

    4. 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屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆