• Home
  • Projects
  • Substack
Substack

tmux: Per-project status bar

tmux setup with different status bars for each project
By Przemek, May 2020 (last update September 2023)

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:

A tmux session with a custom green color set for the status bar.

A tmux session with a custom white color set for the status bar.

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 🎉 !

In an earlier version of this post I described using tmuxp to automate the setup. In the end I found it an overkill for this use case and switched to the shell functions above.

    Outline

    • Prerequisites
    • Setting the colors for the status bar
    • Color palettes
    • Automated setup using shell functions
    • Conclusion

    If you liked this and want more ...

    People trying to get along with computers. Things we can do with AI, things we better do ourselves. An occasional segway to Steinbeck's post-rodeo hangover 💫.

    ... check out my weekly column