Changing the tmux status bar

tmux is a terminal multiplexer (and arguably a Window Manager, something I'm very fond of), very similar to GNU screen. But it's about a decade younger, a decade less crufty, and learned a lot from screen's mistakes. The default setup under Debian has a status bar that looks like this:

tmux-Debian default status line - very green.

My prompt is usually dressed in blue and yellow, so I thought the tmux status line should match it:

# ~/.tmux.conf
set -g status-bg blue
set -g status-fg yellow

You may want something less garish. Note that if tmux is already running, starting another instance will use the config from the running instance - NOT the newly edited config. This changes the colours, as expected:

tmux-Debian default status line - now in yellow and blue.

I also like my date and time displayed a particular way, and wanted the battery status added:

set -g status-right '#[fg=red,bg=blue] #(tmux.powavail)#(tmux.batt)%% #[fg=yellow]%a %Y-%m-%d %H%M'

If all that percentage stuff at the end is confusing, read man strftime - it's essentially time formatting. What I'm mostly doing here is adding power display to the status bar: I created specific scripts for it, namely tmux.powavail and tmux.batt. These versions are for the Linux, but the Mac version is included and commented out:

# ~/bin/tmux.batt
# Returns the battery percentage value for the tmux status line

# Mac version:
#pmset -g batt | tail -1 | awk '{print $2}' | tr -d ';' | tr -d '%'

# Linux version:
cat /sys/class/power_supply/BAT?/capacity
# ~/bin/tmux.powavail
# Returns "^" if power is plugged in, "v" if it isn't (or "-" if fully
# charged under Linux):

# Mac version:
#case $(pmset -g batt | tail -1 | awk "{ print \$3 }" | tr -d ";") in
#    discharging)
#        echo "v"
#    ;;
#    charging)
#        echo "^"
#    ;;

# Linux version:
case $(cat /sys/class/power_supply/BAT?/status) in
   Full) echo "-";;
   Discharging) echo "v";;
   Charging) echo "^";;
   *) echo "?";;

Putting it inline might be nice, but escaping pipes, quotes and commands in tmux status lines is apparently a nightmare so I skipped it entirely. Here's the final result:

tmux's status line - yellow and blue, with my preferred date style and the battery status.