The week between Christmas and New Year is when I tidy the things I have been tolerating all year, and this year it was my shell prompt. Mine had grown into a cluttered line that told me everything and therefore nothing. So I tore it down and rebuilt it around a single question: what do I actually look at before I press Enter?
The honest answer is short. Where am I. What branch am I on, and is the working tree dirty. Did the last command succeed. That is most of it. Everything else, the time, the full hostname, the username I already know, was noise dressed up as information.
The single best thing I added is the exit status of the last command, but only when it is non-zero. A green prompt means the last thing worked and I don't need to think about it. The moment something fails, the prompt character goes red and the code appears, so a silent failure can no longer slip past me. In zsh that is two prompt-expansion conditionals:
# red prompt char + exit code on failure, green otherwise
PROMPT='%(?.%F{green}.%F{red}%? )%#%f '
The git status I lean on vcs_info for rather than hand-rolling, because parsing git status in a precmd hook is a well-trodden way to make every prompt feel laggy in a big repo. vcs_info is built into zsh, it is fast enough, and it gives me the branch and a dirty marker without shelling out a dozen times:
autoload -Uz vcs_info
precmd() { vcs_info }
zstyle ':vcs_info:git:*' formats ' (%b%u%c)'
zstyle ':vcs_info:*' check-for-changes true
setopt prompt_subst
RPROMPT='%F{yellow}${vcs_info_msg_0_}%f'
I put the git block on the right-hand side using RPROMPT. This is the small detail I am most pleased with. The branch and dirty state sit over on the right, out of the way, and the left edge stays clean and predictable so my commands always start in the same place. When I paste something or scroll back, the right-hand prompt politely disappears rather than cluttering the history. It is a lovely bit of zsh that I wish I had used years ago.
The rule I held myself to was that every element had to earn its place by answering "would I have made a mistake without this?" The current directory: yes, I have absolutely run a destructive command in the wrong folder. The branch: yes, I have committed to the wrong one more than once. The exit code: yes, I have moved on from a command that quietly failed. The decorative Unicode powerline arrows that were eating half a line: no, never once saved me from anything. Gone.
It took an evening, most of which was spent resisting the urge to add things back in. The result is a prompt I barely notice, which is exactly the point. A good prompt is like good plumbing. You only think about it when something is wrong, and now, when something is wrong, it goes red and tells me. Worth the evening.