【问题标题】:Unix script to launch multple projects from terminal从终端启动多个项目的 Unix 脚本
【发布时间】:2020-04-10 15:23:42
【问题描述】:

我有什么?

  • 我在 Nodejs 和 Angularjs 中有多个项目,它们彼此依赖
  • 我曾经cd到每个项目目录并为该项目运行相应的命令。
  • 为此,我需要记住我应该使用哪个命令来运行每个项目。
  • 每个项目可能需要多个命令才能运行。 (例如:启动 ui 和后端)
  • 所有项目都在同一个目录中。

我想要什么?

  • 我想要一个脚本,它可以为我要运行的每个项目打开唯一的终端选项卡
  • 标签名称也应类似于项目名称和其标题中运行的命令

【问题讨论】:

    标签: shell unix terminal scripting tabs


    【解决方案1】:

    脚本

    # Set your parent directory, where all projects would be present
    projDir='/home/yatishbalaji/projects/'
    
    # Declare list of projects along with the command to run.
    # If u want to run multiple commands per project (eg: ui and backend), 
    # seperate commands with `;`, and this script will open them in different tabs
    
    declare -A MYMAPS=(
    ["manage"]="grunt serve"  
    ["hire"]="gulp serve" 
    ["billing"]="npm run startApi;npm run startUI;npm run startLambda"
    ["algo"]="npm run dev"
    );
    
    launchCmd=''
    
    for app in "$@"; do
            STR=${MYMAPS[$app]}
        IFS=';'
        read -ra commandArr <<< "$STR"
    
        for command in ${commandArr[*]}; do
                cmd='cd '$projDir$app' && '$command
            launchCmd+=(--tab -t "$app=>$command" -e "bash -c '$cmd';bash")
    #       launchCmd+=(--tab -t "$app=>$command" --working-directory="$projDir$app" -e "bash -c '$command';bash")
        done
    done
    gnome-terminal "${launchCmd[@]}";
    # mate-terminal "${launchCmd[@]}"
    exit 0;
    

    如何使用?

    将项目名称(您要打开的)作为参数传递给您的脚本

    bash ~/launchApps.sh manage billing

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      • 1970-01-01
      • 1970-01-01
      • 2017-12-12
      相关资源
      最近更新 更多