I often have multiple tmux sessions running at the same time in separate windows, corresponding to different projects – wouldn’t it be nice to have some visual indication to easily tell one session from the other?
For example, could it look something like this:
In this note we describe a setup that automatically bootstraps the tmux session for different projects and configure it so that different colors are used for the status bar, depending on the project.
Prerequisites
I tested this setup on Debian Linux and Mac with tmux 3.0.
Make sure to have the
following option in the .tmux.conf
file to ensure the 8-bit color palette is
handled correctly
:
set-option -g default-terminal "screen-256color"
Setting the colors for the status bar
We can experiment with different status bar colors while in a tmux session:
tmux set status-style bg=colour22,fg=colour255
Color palettes
Here are a few color combinations I like:
[blog] 0:shell- 1:nvim*
→bg=colour22,fg=colour255
[blog] 0:shell- 1:nvim*
→bg=colour254,fg=colour0
[blog] 0:shell- 1:nvim*
→bg=colour3,fg=colour255
[blog] 0:shell- 1:nvim*
→bg=colour89,fg=colour255
We can build more combinations using this
color pallette
by Jonas
Jacek. Just make sure to refer to colors as colour<number>
, because I found
the Xterm names to usually not work on my machines.
Automated setup using shell functions
Small bashrc / zshrc functions can be used to automate bootstrapping:
function init-blog {
cd ~/projects/blog
tmux new-session -d -s blog
tmux set -t blog status-style bg=colour22,fg=colour255
tmux attach-session -t blog
}
function init-piosenka {
cd ~/projects/piosenka
tmux new-session -d -s piosenka
tmux set -t piosenka status-style bg=colour254,fg=colour0
tmux attach-session -t piosenka
}
Conclusion
That’s it! Thanks to these we can launch the desired style of session simply by
typing init-blog
or init-piosenka
🎉 !