Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 在不同选项卡窗口中并发执行脚本_Git_Bash_Osascript - Fatal编程技术网

Git 在不同选项卡窗口中并发执行脚本

Git 在不同选项卡窗口中并发执行脚本,git,bash,osascript,Git,Bash,Osascript,我正在尝试在不同的Mac终端标签中同时克隆git repo,因为克隆需要很长时间 我已经尝试了下面的许多变体,但似乎无法获得每个单独的克隆,然后在3个单独的终端选项卡中同时运行以下命令,关于如何在不安装外部设备(如ttab)的情况下更改下面的命令来实现这一点,有什么想法吗 cwd=$(pwd) osascript -e 'tell application "Terminal" to activate' -e 'tell application "System Events" to tell pr

我正在尝试在不同的Mac终端标签中同时克隆git repo,因为克隆需要很长时间

我已经尝试了下面的许多变体,但似乎无法获得每个单独的克隆,然后在3个单独的终端选项卡中同时运行以下命令,关于如何在不安装外部设备(如ttab)的情况下更改下面的命令来实现这一点,有什么想法吗

cwd=$(pwd)
osascript -e 'tell application "Terminal" to activate' -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' -e 'tell application "Terminal" to do script "cd '$cwd' && git clone git@github.com:me/myrepo1.git && cd myrepo1 && git pull && nvm use && npm install &" in selected tab of the front window' &
osascript -e 'tell application "Terminal" to activate' -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' -e 'tell application "Terminal" to do script "cd '$cwd' && git clone git@github.com:me/myrepo3.git && cd myrepo2 && git pull && nvm use && npm install" in selected tab of the front window' &
git clone git@github.com:me/myrepo3.git && cd myrepo3 && git pull && nvm use && npm install
这就行了

#!/bin/bash

declare -a repos=("myrepo1" "myrepo2" "myrepo3")
me="git@github.com:me"

pwd=`pwd`
for i in "${repos[@]}"
do
  osascript -e "tell application \"Terminal\"" -e "tell application \"System Events\" to keystroke \"t\" using {command down}" -e "do script \"cd $pwd; git clone $me/$i.git && cd $i && git pull && nvm use && npm install\" in front window" -e "end tell" > /dev/null
done

注:

  • 在克隆回购协议之后,您不必使用
    git pull
    ,但我还是将其保留在脚本中,因为它不会造成任何伤害
  • 如果使用
    nvmuse
    ,请确保每个项目的根目录中都有一个
    .nvmrc
    文件,其中包含指定的节点版本。否则,
    nvm use
    将不起作用。
    • 你可能已经知道了,但我想在 如果你的脚本没有运行
没问题:)我很高兴这有帮助。