aliquote

< a quantity that can be divided into another a whole number of time />

My Tmux in 2021

August 5, 2021

I’ve been using Tmux since 2013, and I wrote a blog post at that time. I somehow revisited my setup last year, but it was still on macOS (and using iTerm2). In the mean time I switched to Kitty, and I enjoyed using it for over a year and a half or so. It worked well in practice, I could use it on my Macbook and even on an OpenBSD machine. Same configuration, multiple OSs – what else? The only thing that I was really missing was getting notification for new activity in other tabs, session management and keyboard-based copy-pasting.

A few weeks ago, I decided to go back to the defaults (since default settings are often good, you know) and use Gnome terminal, which looks like a great terminal emulator, but without ligature support or multiplexing capabilities. Yet we can manage to get a comfy setup by adding Tmux on top of that. Hence I revised for the third time my Tmux config. I’ve been using Byobu on a remote server last year, but finally it didn’t bring me much more and I could do everything I wanted with Tmux alone. In fact, the only thing I really liked in Byobu was its ability to notify about available updates and reboot info so that my status config file ended up with just those items:

tmux_left="session"
tmux_right="reboot_required updates_available load_average"

Since Byobu can use your screen or tmux config files, most of my settings remained in my .tmux.conf file, and it acted as yet another backend.

I am now using Tmux every day, and it goes as smoothly as when I was using Kitty, except that I now have a few additional optins: I can switch my theme easily thanks to Gnome terminal, and I can manage multiple sessions at the same time. I can also detach the current session and close Gnome terminal, I know I will be able to restore everything afterwards unless I rebooted Ubuntu. Here are the core components of my Tmux setup:

As for the status bar, it is usually a matter of opinion: I for one do not want to rely on external plugins (I can uptime or date myself in the terminal), and I want a minimalist design. Here we go:

tmux

And here is the code:

set -g status-interval 5
set -g status-justify left
set -g status-left ""
set -g status-position top
set -g status-right "#[fg=colour3] ♯#S "
if '! [ -z "$SSH_TTY" ]' 'set -g status-right "#[fg=colour145] #(whoami)@#h #[fg=colour3] ♯#S "'
set -g status-style fg=colour145
set -g window-status-current-format "#[fg=colour11,bg=colour3] #I "
set -g window-status-format "#[fg=colour145] #I "
set -g window-status-separator "#[fg=colour145]"

[2021-08-22]
If you decide to only show window number like in the above settings you may loose some critical information, especially zoomed pane (window activity keep being highlighted when setting setw -g monitor-activity on). If you don’t want to add all flags (#F), you can still replace set -g window-status-current-format "#[fg=colour11,bg=colour3] #I " with set -g window-status-current-format "#[fg=colour7,bg=colour4] #I#{?window_zoomed_flag,+,} ", or even highlight other flags using convenient marks. I updated my config to display zoomed panes since I use this a lot and I sometimes forgot about them.

Finally, beside personal keybindings, here are some useful builtin keybindings I keep using regularly:

I sometimes want to create a new session and attach the current window to it. Here is how we can do: Create a new session using <prefix> + :new, then <prefix> + :move-window -s #name:#pane, where #name is the name of the current session in which the #pane number is. A typical command is :move-window -s main:2 to move “pane number 2” (from session “main”) to the newly created session.

That’s it! I hope you will enjoy Tmux.

unix

See Also

» Some handy Git aliases » Neomutt » Timeshift for system backup » Welcome OpenBSD » Little shell scripts are amazing