-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmux-sshrc
31 lines (25 loc) · 947 Bytes
/
tmux-sshrc
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
# Source this file in your shell startup, i.e. bashrc, zshrc, etc.
# Wrap ssh commmand to allow smart pane behavior in tmux.
#
# After opening a tmux window and ssh-ing into another server, new panes will
# open already ssh-ed to the server.
function ssh() {
if [ -n "$TMUX" ] # set only if within running tmux
then
window_index=$(tmux display-message -p '#I')
# arbitrary environment variable name to remember ssh args like server
# hostname so we can connect again.
session_variable_name="window_${window_index}_ssh_args"
# save in tmux session variable
tmux setenv $session_variable_name "$*"
# run ssh
/usr/bin/ssh $*
# unset variable so new panes don't continue ssh-ing to this server
tmux setenv -u $session_variable_name
else
/usr/bin/ssh $*
fi
}
# shell variable used in tmux conf to determine where script is
export TMUX_SSH_DIR=$(dirname $(readlink -f $0))
# vim: set ft=sh: