The tmux status bar isn’t just for showing session info; it’s a dynamic, programmable display that can become your command center, reflecting anything you can script.

Let’s see it in action. Imagine you’re deep in a server room, monitoring a critical service. You want to know its health at a glance without switching windows.

# ~/.tmux.conf

# Basic setup
set -g status on
set -g status-left '#[fg=green]Session: #S #[fg=yellow]#I #[fg=cyan]#P'
set -g status-right '#[fg=green]%Y-%m-%d %H:%M:%S'

# Add a custom script to show git branch
set -g status-right '#(git_prompt_info 1) #[fg=green]%Y-%m-%d %H:%M:%S'

# Configure colors
set -g status-style 'bg=colour235,fg=colour250'
set -g status-left-style 'bg=colour238,fg=colour250'
set -g status-right-style 'bg=colour238,fg=colour250'

In this config:

  • set -g status on ensures the status bar is always visible.
  • set -g status-left defines what appears on the left. #S is the session name, #I is the window index, and #P is the pane index. We’re coloring them for readability.
  • set -g status-right defines the right side. %Y-%m-%d %H:%M:%S shows the current date and time.
  • #(git_prompt_info 1) is a command executed by tmux. If you have a git_prompt_info script in your PATH, it will run and its output will be inserted here. This is how you add custom information.
  • status-style, status-left-style, status-right-style let you control the background and foreground colors using colourXXX codes (256-color palette) or standard names like red, blue.

This setup gives you a basic but informative status bar. The real power comes from the segments and scripts.

Understanding Segments

Tmux status bar segments are special keywords or command outputs that tmux can display. They’re enclosed in #[] for styling and () for command execution.

Common segments:

  • #S: Session name
  • #I: Window index
  • #P: Pane index
  • #W: Window name
  • #H: Hostname
  • #h: Short hostname
  • #(command): Output of command
  • #[]: For styling, e.g., #[fg=red,bg=yellow]

Scripting Your Status Bar

This is where the magic happens. You can run any shell command and have its output displayed. This allows for dynamic information like:

  • System Load: #(cut -d. -f1 /proc/loadavg)
  • Battery Status: #(cat /sys/class/power_supply/BAT0/capacity)% (adjust path for your system)
  • Network Speed: You’d need a script here, perhaps using vnstat or ifstat.
  • Git Branch/Status: As shown in the example, a simple script can parse .git/HEAD or use git status --porcelain.

Let’s flesh out the git_prompt_info script for the example:

# In your PATH, e.g., ~/.local/bin/git_prompt_info
#!/bin/bash

# Check if we are in a git repository
if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
  # Get branch name
  branch=$(git symbolic-ref --short HEAD 2>/dev/null)
  if [ -z "$branch" ]; then
    branch=$(git rev-parse --short HEAD 2>/dev/null) # detached HEAD
  fi

  # Check for changes
  if git diff --quiet --ignore-submodules HEAD 2>/dev/null; then
    # No changes
    echo "#[fg=green]git:$branch"
  else
    # Uncommitted changes
    echo "#[fg=yellow]git:$branch*"
  fi
else
  echo "#[fg=red]not git"
fi

This script checks if you’re in a git repo. If so, it finds the branch name and checks for uncommitted changes, coloring the output accordingly.

Advanced Customization

You can create complex layouts by chaining segments and commands. For example, showing disk usage for a specific mount point:

set -g status-right '#(df -h / | awk "NR==2 {print \$5 \" \" \$4}") #[fg=green]%Y-%m-%d %H:%M:%S'

This adds 5% / (5% used, / available) to your status line.

The real power of tmux is its ability to integrate with your workflow. You’re not limited to predefined segments; you can build a dashboard for your specific needs. The status bar becomes an active part of your development environment, not just a passive display.

The most surprising thing about tmux’s status bar is how easily it can become a distributed system monitor, pulling data from remote machines via SSH commands executed within #(command).

The next challenge is managing the complexity of many custom scripts and ensuring they don’t slow down your tmux instance.

Want structured learning?

Take the full Tmux course →