Create a gist now

Instantly share code, notes, and snippets.

Embed
Set tmux pane title to short hostname on ssh connections
ssh() {
if [ "$(ps -p $(ps -p $$ -o ppid=) -o comm=)" = "tmux" ]; then
tmux rename-window "$(echo $* | cut -d . -f 1)"
command ssh "$@"
tmux set-window-option automatic-rename "on" 1>/dev/null
else
command ssh "$@"
fi
}
@maptracker

This comment has been minimized.

Show comment
Hide comment
@maptracker

maptracker Jun 29, 2016

Thanks for this! It is unhappy with flags on ssh (like -X) though. I used another trick to get just the last argument:

tmux rename-window "$(echo $* | rev | cut -d ' ' -f1 | rev | cut -d . -f 1)"

Thanks for this! It is unhappy with flags on ssh (like -X) though. I used another trick to get just the last argument:

tmux rename-window "$(echo $* | rev | cut -d ' ' -f1 | rev | cut -d . -f 1)"
@javipolo

This comment has been minimized.

Show comment
Hide comment
@javipolo

javipolo May 24, 2018

Thanks a lot, I've been using this for quite a long time, and I decided to improve it by:

  • Do not use short name if it's an IP address
  • Putting everything into functions that can be reused by any other command
  • Determine the proper window ID to restore after the command. If not, in case the ssh failed while you were working on other window, it would restore the automatic-rename setting in the active window instead of the proper one

https://gist.github.com/javipolo/62eb953f817a9a2f63b8127ff5f60788

Thanks a lot, I've been using this for quite a long time, and I decided to improve it by:

  • Do not use short name if it's an IP address
  • Putting everything into functions that can be reused by any other command
  • Determine the proper window ID to restore after the command. If not, in case the ssh failed while you were working on other window, it would restore the automatic-rename setting in the active window instead of the proper one

https://gist.github.com/javipolo/62eb953f817a9a2f63b8127ff5f60788

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment