Embedded shell commands
status-right shows cat ~/status.txt, refreshed every 5 seconds, and the file now reads FAILED.
One character apart, two different things:
#{...}- a format, expanded by tmux itself
#(...)- a shell command; tmux runs it and shows the output
status-interval- how many seconds may pass before it runs again
How the command behaves decides how the bar behaves. A command that prints one line and exits is shown until the next rerun. A command that keeps running — a while loop with a sleep in it — updates the bar every time it prints. Reruns happen at most once a second, and at least every status-interval.
Press C-b :, type set -g status-right '#(cat ~/status.txt) %H:%M', Enter.
The bar’s right end reads build: ok and the time.
Press C-b :, type set -g status-interval 5, Enter.
The bar will now refresh at least every five seconds.
Run echo 'FAILED' > ~/status.txt.
Within five seconds the bar reads FAILED.
Escaping percent signs
A % in the command’s output must be doubled to %%, or tmux reads it as a date code.
Here is what just happened.
tmux ran cat once immediately, then on the interval. Editing the file never touched tmux; the next scheduled rerun read the new line. The clock next to it is expanded by tmux itself on every redraw.
- Run a command and show its output, re-run at most every status-interval seconds:set -g status-right '#(cmd)'
- Maximum seconds between status line refreshes:set -g status-interval 5
Go further
'#(tail -f ~/status.txt)'stays running and updates the moment the file gains a line.status-lefttakes embedded commands the same way.- If the command fails, tmux leaves the last good output in place.
- 1Keep
%H:%Min the value so the clock stays:set -g status-right '#(cat ~/status.txt) %H:%M'. - 2
#(...)runs a shell command where#{...}would read a format. - 3
set -g status-interval 5, thenecho FAILED > ~/status.txtand wait a few seconds.
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-right contains an embedded command that cats status.txt— not done yet
- status-interval is set to 5 seconds— not done yet
- status.txt now reads FAILED, so the status line has something new to show— not done yet