简体   繁体   English

如何从 shell 脚本从 VSCode 终端运行命令?

[英]How to run a command from VSCode terminal from shell script?

I am trying to make simple shell script where it will launch a couple of projects in the same directory at the same time then run npm script to start server/dev mode.我正在尝试制作简单的 shell 脚本,它将同时在同一目录中启动几个项目,然后运行 npm 脚本来启动服务器/开发模式。

For instance, lets just assume I have api, web-client, admin-client.例如,假设我有 api、web-client、admin-client。
I want my shell script to do following:我希望我的 shell 脚本执行以下操作:

If file name matches the file I want to open with VSCode, then it will launch.code command.如果文件名与我想用 VSCode 打开的文件匹配,那么它将 launch.code 命令。 Then not inside the current terminal that I am running shell script, but inside the "VSCode" terminal, I would like to run npm script recursively for all the files within the same directory.然后不在我正在运行 shell 脚本的当前终端内,而是在“VSCode”终端内,我想为同一目录中的所有文件递归运行 npm 脚本。

The purpose of this is to automate routine setup process to start up development.这样做的目的是自动化常规设置过程以启动开发。

Question: How to run a command from VScode terminal when I am running below shell script on external terminal?问题:当我在外部终端上的 shell 脚本下运行时,如何从 VScode 终端运行命令?

below is my current code:以下是我当前的代码:

for D in ./*;
  do
    if [ -d "$D" ]; then
        cd "$D"
        mydir="$(basename $PWD)"
        if [ $mydir == "api" ]
          then
            echo launching $mydir ...
            code .
            #command to run inside vscode : npm run start:server
            cd ..
        elif [ $mydir == "web-frontend" ]
          then
            echo launching $mydir ...
            code .
            cd ..
        elif [ $mydir == "admin-frontend" ]
          then
            echo launching $mydir ...
            code .
            
            cd ..
        else
          cd ..
        fi
    fi
  done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM