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

my prompt should answer questions before i ask them

A short note on building a shell prompt that surfaces git branch, exit status and host context so I stop typing the same status commands all day.

A mechanical keyboard lit by a terminal

I spent years with a prompt that just said where I was, then typed git status and git branch a hundred times a day to find out everything it didn't tell me. At some point the obvious occurred to me: the prompt is the one piece of text I read constantly, so it should carry the things I'm forever asking for.

Mine now shows four bits and nothing else. The branch and a marker if the tree is dirty. The exit code of the last command, but only when it wasn't zero, so a red 127 shouts at me instead of hiding in scrollback. The hostname, coloured per machine, because I have logged into the wrong box and run the wrong thing more than once. And a ± if I'm a kubectl context away from production, which is the cheapest insurance I own.

PROMPT='%F{cyan}%m%f %~ $(git_dirty)%(?..%F{red}✗%?%f )%# '

The rule I've settled on is that a prompt earns its space by replacing a command I'd otherwise type. Anything decorative gets cut. A glowing two-line powerline thing is lovely in a screenshot and a distraction by Thursday. Plain text, coloured where it matters, quiet where it doesn't. It reads the room so I don't have to.