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

A Shell Prompt That Tells Me What I Need

Building a shell prompt that surfaces the context I actually use, and ruthlessly hiding everything I don't.

A keyboard and terminal

My prompt used to be a tiny novel. Full hostname, full path, git branch, git status symbols, language version, the time, a battery indicator, and a little arrow that changed colour for reasons I'd long forgotten. It looked impressive in screenshots and told me almost nothing useful, because when everything is on screen, nothing stands out. The job of a prompt isn't to show off what it can detect. It's to tell me the one thing that's about to bite me.

So I stripped it back and rebuilt around a single question: what do I need to know before I press enter? Everything that survives the prompt has to earn its place by answering that.

Code on a screen

What stayed, and why:

  • The path, shortened. I almost never need the full path. I need to know I'm in the right repo and roughly where. So the prompt shows the last couple of segments and collapses the rest. Enough to orient, not enough to wrap the line.
  • Git state, but only when it's interesting. A clean branch is quiet. The moment there's something uncommitted, ahead/behind the remote, or a stash, then it speaks up. The default state is silence, and silence means "nothing to worry about".
  • A warning when I'm somewhere dangerous. This is the one that actually changed my behaviour. If I'm on a production host, or kubectl is pointed at a context that can hurt people, the prompt goes loud and a colour I can't ignore. The whole point is that the warning only appears when the warning matters.

What went, and why:

  • The clock. My terminal multiplexer already shows the time. Two clocks is one clock too many.
  • Language version badges. I don't switch runtime versions often enough mid-session to need it on every line. When I do care, I'll ask. A version manager telling me on every prompt is answering a question I rarely have.

The mechanism is dull and that's a feature. It's a function that runs before each prompt, checks a handful of cheap things, and emits a string. The only rule I held to is that it has to be fast. A prompt that adds even a noticeable fraction of a second between commands is a tax you pay all day, so anything slow gets cached or dropped. If detecting something costs more than the information is worth, it doesn't go in.

The result is a prompt that's blank and calm most of the time, and shouts exactly when I need it to. The day it stopped me running a destructive command against the wrong cluster, because the context badge was glowing red and I actually noticed, it paid for every minute I spent tuning it. That's the whole brief: quiet until it isn't, and right when it speaks.