learntmux.dev

Embedded shell commands

Goal

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.

Do this

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.

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-right contains an embedded command that cats status.txt— not done yet
  2. status-interval is set to 5 seconds— not done yet
  3. status.txt now reads FAILED, so the status line has something new to show— not done yet