Terminal Titles for TMUX

Linux Jun 16, 2021

The problem

Some of you know, I use TMUX mostly for logging and handling my zsh plugin cLoggy.‌‌ From time to time I noticed with tenth of terminal tiles open, the contents of my terminals was not always obvious to me.

As soon as you start tmux in your terminal it goes from this:

Proper window name with current working dir

to Gnome-Terminal or just freezes with your last path.

There are plenty of tmux native solutions people came up with but none of them truly worked for my scenarios. SSHing to another box would not update the title any more or the title was missing the wanted information about my current path.

Solution

The way I got the stuff working was to use ZSH and Bash functionality in order to update the naming for all panes. You should apply the changes to your config files to all hosts you SSH to as well.

  1. In your ~/.tmux.conffile(s)
set-option -g set-titles on
  1. In your /etc/profile (for bash sessions)
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
  1. In your ~/.zshrc file(s)
precmd() {
	echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"
}

You will end up with the following naming scheme:
tmux-session-name:pane-number:current-app - "user@host:path"

Title of some stacked i3 tiles with and without SSH sessions

There are plenty of other ways you can create this naming scheme but I like it this way.
If you are crazy enough like me you can even nest your tmux sessions and still know what you're looking at ;)

Active remote top left
Active local right
Active remote bottom left

I hope you enjoyed this entry. It will give you more passive control about your lateral situation in tiling window managers! ;)

Tags