Ramblings of an aging IT geek
← Ramblings of an aging IT geek
tooling

a shell prompt that tells me what i need

How I trimmed my shell prompt down to the three things I actually look at, and nothing else.

A keyboard in front of a terminal

For years my prompt was a wall of colour: full path, hostname, time, battery, the phase of the moon. I looked at almost none of it. The signal I actually want, every time, is whether the last command failed and which git branch I'm on. So I cut everything else.

What survived: a $ that goes red when the previous exit code is non-zero, the current branch with a marker if the tree is dirty, and a short path that only shows the last couple of segments. That's the lot. No timestamp, because history has the timestamp. No hostname, because my terminal title already carries it.

PROMPT='%(?.%F{green}.%F{red})$%f $(git_branch) %1~ '

The git bit is a tiny function that prints nothing outside a repo, so non-git directories stay clean. The trick that made it fast was caching the dirty check rather than shelling out to git status on every keystroke; on a big repo the naive version added a visible pause before each prompt, which is exactly the sort of thing that makes you quietly hate your own setup.

The lesson, if there is one: a prompt is a dashboard, and a dashboard with forty gauges tells you nothing. Three things I read in a glance beats forty I scroll past.