-
-
Save nevesnunes/951f77085116a9beea62c9610dda31e8 to your computer and use it in GitHub Desktop.
Set tmux pane title to short hostname on ssh connections
This file contains 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
ssh() { | |
# grep -w: match command names such as "tmux-2.1" or "tmux: server" | |
if ps -p $$ -o ppid= \ | |
| xargs -i ps -p {} -o comm= \ | |
| grep -qw tmux; then | |
# Note: Options without parameter were hardcoded, | |
# in order to distinguish an option's parameter from the destination. | |
# | |
# s/[[:space:]]*\(\( | spaces before options | |
# \(-[46AaCfGgKkMNnqsTtVvXxYy]\)\| | option without parameter | |
# \(-[^[:space:]]* | option | |
# \([[:space:]]\+[^[:space:]]*\)\?\)\) | parameter | |
# [[:space:]]*\)* | spaces between options | |
# [[:space:]]\+ | spaces before destination | |
# \([^-][^[:space:]]*\) | destination | |
# .* | command | |
# /\6/ | replace with destination | |
tmux rename-window "$(echo "$@" \ | |
| sed 's/[[:space:]]*\(\(\(-[46AaCfGgKkMNnqsTtVvXxYy]\)\|\(-[^[:space:]]*\([[:space:]]\+[^[:space:]]*\)\?\)\)[[:space:]]*\)*[[:space:]]\+\([^-][^[:space:]]*\).*/\6/')" | |
command ssh "$@" | |
tmux set-window-option automatic-rename "on" 1> /dev/null | |
else | |
command ssh "$@" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment