Formats and embedded styles
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:
awhile the condition holds,botherwise #[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.
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 40Press 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.
Here is what just happened.
The bar redraws on every change, and each redraw re-evaluates the conditional: client_prefix flips to 1 while you hold the prefix, so the format expands to #[fg=red]. #[default] after P stops the colour bleeding into the rest, and status-left-length 40 gave the longer value room.
- Formats expand attributes of the server, session, window or pane:set -g status-left '#{session_name}'
- Change the style of the following text until the next #[...]; #[default] resets:#[fg=red]
- Allow a longer status-left:set -g status-left-length 40
Go further
display-message -p '#{session_name} #{window_index}'expands a format on the spot, to test one before it goes in the file.show -gv status-rightshows the default right side, which already uses a conditional for the pane title width.bg=works in embedded styles too:#{?client_prefix,#[bg=red],#[bg=default]}.
- 1Do not run
tmux attachagain; you are already attached. Load the file withC-b :thensource ~/.tmux.conf. - 2A conditional is
#{?condition,if-true,if-false}.client_prefixis1while the prefix is held, so#{?client_prefix,#[fg=red],#[fg=green]}picks a style. - 3Put
Pafter the conditional and#[default]afterP, then the session name in its own colour. Setstatus-left-length 40too. - 4Full line:
set -g status-left '#{?client_prefix,#[fg=red],#[fg=green]}P#[default] #[fg=cyan]#{session_name}#[default] '.
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
Alpine Linux and tmux 3.4 on an x86 emulator. Nothing to install, and no server behind it.
about 15 MB, once
Done when
not started- status-left contains an embedded style, which the default does not— not done yet
- status-left contains a conditional on client_prefix— not done yet
- status-left-length is at least 30— not done yet