-
-
Save W4RH4WK/76a435e5d7c2a19d27f4 to your computer and use it in GitHub Desktop.
Tmux run program in parallel
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
| #!/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