learntmux.dev

Formats and embedded styles

Goal

status-left shows a P that turns red while the prefix is held, then the session name.

Three pieces of syntax turn the status line from a label into something that reacts:

#{session_name}
a format: expands to a value tmux knows
#{?client_prefix,a,b}
a conditional: a while the condition holds, b otherwise
#[fg=red]
an embedded style: colours the text after it, until #[default]

Formats read the server’s live state — session, window, pane and client attributes. client_prefix is 1 only while a client is waiting for the key after the prefix, which is what makes the indicator flash.

status-left-length caps how much of the value is actually drawn, and the default is too short for the line you are about to write.

Do this

Run open ~/.tmux.conf, add these lines, and save with Ctrl-S:

set -g status-left '#{?client_prefix,#[fg=red],#[fg=green]}P#[default] #[fg=cyan]#{session_name}#[default] '
set -g status-left-length 40

Press C-b :, type source ~/.tmux.conf, Enter.

The bar starts with a green P and learn in cyan.

Press and hold C-b.

P turns red; release, and it is green again.

What counts as true

A conditional counts as true when its value is non-zero and non-empty, so most flag-style formats can be used directly.

Stuck on this one?

This is a live terminal. Typing goes to the machine, including Tab. Press Shift and Tab together to move focus back out to the page.

A real terminal, in this tab

about 15 MB, once

session learn

Done when

not started
  1. status-left contains an embedded style, which the default does not— not done yet
  2. status-left contains a conditional on client_prefix— not done yet
  3. status-left-length is at least 30— not done yet