Created
August 7, 2015 08:35
-
-
Save ejoubaud/d9311c280cc4b5a45f06 to your computer and use it in GitHub Desktop.
Open variations of a command in multiple iTerm2 panes. Works with bash and zsh.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
multicom () { | |
echo Usage: multicom command arg1 arg2 arg3 arg4... | |
echo e.g. multicom "ssh %s" web1 web2 web3 | |
echo | |
read -r -d '' code <<-APPLESCRIPT | |
activate application "iTerm" | |
tell application "System Events" to keystroke "n" using command down | |
APPLESCRIPT | |
command=${@:1:1} | |
echo $command | |
i=0 | |
for comarg in ${@:2}; do | |
key=d | |
# Open a new tab every 3 panes | |
((i+=1)) | |
if [ $((i%3)) -eq 0 ]; then | |
key=t | |
fi | |
read -r -d '' code <<-APPLESCRIPT | |
$code | |
tell application "iTerm" to tell session -1 of current terminal to write text "$(printf "$command" $comarg)" | |
tell application "System Events" to keystroke "$key" using command down | |
APPLESCRIPT | |
done | |
echo "$code" | |
osascript -e "$code" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment