Skip to content

Instantly share code, notes, and snippets.

@ejoubaud
Created August 7, 2015 08:35
Show Gist options
  • Save ejoubaud/d9311c280cc4b5a45f06 to your computer and use it in GitHub Desktop.
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.
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