Created
October 25, 2024 22:35
-
-
Save mlaugharn/632173d096cba0357bb73dfcdb0eae76 to your computer and use it in GitHub Desktop.
broadcast commands in parallel to tmux panes
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 | |
# Usage: ./tmux-parallel.sh "command1" "command2" "command3" ... | |
# Creates a new tmux window with a pane for each command | |
if [ $# -eq 0 ]; then | |
echo "Usage: $0 command1 [command2 ...]" | |
exit 1 | |
fi | |
# Get the current tmux session or start a new one | |
if [ -z "$TMUX" ]; then | |
tmux new-session -d | |
fi | |
# Create a new window | |
window_name="parallel-$(date +%s)" | |
tmux new-window -n "$window_name" | |
# For the first command, we'll use the existing pane | |
tmux send-keys -t "$window_name" "${1}" C-m | |
# For each additional command, create a new pane and split | |
shift | |
while [ $# -gt 0 ]; do | |
tmux split-window -t "$window_name" | |
tmux send-keys -t "$window_name" "${1}" C-m | |
tmux select-layout -t "$window_name" tiled | |
shift | |
done | |
# Select the first pane | |
tmux select-pane -t "$window_name.0" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment