Last active
August 29, 2015 14:14
-
-
Save debugloop/7ae4612f2e8025b7cb6e to your computer and use it in GitHub Desktop.
Naming tmux windows for the hosts you ssh to
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
# The following snippet goes into your .zshrc | |
# You probably want to set all occurrences of 'local' to your preferred default name. | |
# This also works well when replacing ssh with mosh or something similar. | |
# To set the default window name in your .tmux.conf, use this line | |
# set-option -g default-command "tmux rename-window local; zsh" | |
ssh() { | |
if [[ $(tmux display-message -p '#W') = "local" ]]; then | |
trap "tmux rename-window 'local'" INT PIPE EXIT # clean up after ctrl-c, broken pipes and other exits | |
test -n "$TMUX" && tmux rename-window "$(echo "${@: -1}" | cut -d '@' -f 2)" # name the window, but ignore the uid if present | |
command ssh "$@" | |
tmux rename-window -t:"$(echo "${@: -1}" | cut -d '@' -f 2)" 'local' # name it back to local | |
trap - INT PIPE EXIT # clear the trap | |
else | |
command ssh "$@" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment