-
-
Save nickrw/8b2850588376d64898fc to your computer and use it in GitHub Desktop.
mux - takes a session name (optional) and list of hosts - then creates a new tmux session and opens SSH connections to the hosts in split 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 | |
ssh="ssh -o StrictHostKeyChecking=no" | |
function split_tmux() { | |
session=$1 | |
shift | |
count=$(echo $@ | tr ' ' '\n' | wc -l) | |
echo "Starting session to $count hosts in $session: [$@]" | |
session="$session ($count)" | |
length=$(echo $session | wc -m) | |
tmux new-session -s "$session" -d "$ssh $1" | |
tmux set-option -t "$session" status-left-length $((length+2)) | |
shift | |
while [[ ! -z $1 ]]; do | |
tmux split-window -t "$session" "$ssh $1" | |
shift | |
done | |
tmux set -t "$session" sync on | |
arrangement=even-vertical | |
if [[ $count -gt 3 ]]; then | |
arrangment=tiled | |
fi | |
tmux select-layout -t "$session" $arrangement | |
tmux -2 attach-session -t "$session" | |
} | |
if [[ -x /usr/bin/keychain ]]; then | |
eval $(keychain --eval -Q --quiet) | |
keychain --agents ssh -Q --quiet ~/.ssh/id_rsa | |
fi | |
case $# in | |
0) | |
echo "Specify a name and host" >&2 | |
exit 1 | |
;; | |
1) | |
session_name=$1 | |
hosts=$1 | |
;; | |
*) | |
session_name=$1 | |
shift | |
hosts=$* | |
;; | |
esac | |
session_name=$(echo $session_name | sed 's/\./_/g') | |
split_tmux $session_name $hosts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment