Skip to content

Instantly share code, notes, and snippets.

@W4RH4WK
Last active November 26, 2015 10:13
Show Gist options
  • Select an option

  • Save W4RH4WK/76a435e5d7c2a19d27f4 to your computer and use it in GitHub Desktop.

Select an option

Save W4RH4WK/76a435e5d7c2a19d27f4 to your computer and use it in GitHub Desktop.
Tmux run program in parallel
#!/bin/bash
# requires:
# set-option -ga update-environment ' TILE_NUM'
SESSION="$(date +%Y-%m-%d-%H-%M-%S)"
TILES="$1"
re='^[0-9]+$'
if [[ ! $TILES =~ $re ]]; then
echo "usage: $0 <num> <cmd>"
echo ' <num> number of tiles'
echo ' <cmd> command to execute'
echo
echo 'Environment variable TILE_NUM will be set per call'
exit 1
fi
shift
CMD="$@"
TILE_NUM='0' TILE_COUNT="$TILES" tmux new-session -s "$SESSION" -d "$CMD"
for i in $(seq 1 $(($TILES - 1))); do
tmux set-environment -t "$SESSION" 'TILE_NUM' "$i"
tmux split-window -t "$SESSION" "$CMD"
tmux select-layout -t "$SESSION" tile
done
tmux attach-session -t "$SESSION"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment