-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh-tmux
More file actions
executable file
·47 lines (35 loc) · 716 Bytes
/
Copy pathssh-tmux
File metadata and controls
executable file
·47 lines (35 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
set -eu
if ! which tmux > /dev/null; then
echo>&2 "$(basename "$0"): tmux: command not found"
exit 3
fi
usage() {
cat >&2 <<EOM
Usage: $(basename "$0") SSH_HOST...
SSH to each SSH_HOST in separate tmux panes.
EOM
}
tmux_cmd() {
tmux send-keys -t $session "$*
"
}
tmux_ssh() {
tmux_cmd "ssh '$1'"
}
if [ $# -lt 1 ]; then
usage
exit 1
fi
session=$(mktemp -u ssh-XXX)
tmux new-session -d -s $session
# should attach to session even if we fail somewhere
trap "tmux attach -t $session" EXIT
first_host="$1"
shift
tmux_ssh "$first_host"
for host in $*; do
tmux split-window -t $session -v
tmux select-layout -t $session even-vertical
tmux_ssh "$host"
done