Skip to content

Instantly share code, notes, and snippets.

@debugloop
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debugloop/7ae4612f2e8025b7cb6e to your computer and use it in GitHub Desktop.
Save debugloop/7ae4612f2e8025b7cb6e to your computer and use it in GitHub Desktop.
Naming tmux windows for the hosts you ssh to
# 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