WORKING FAST AND furious can be great when you are in the zone, but sometimes I work too fast for my own good.
Way too often than I’d care to admit, I will quickly create a new branch:
β± git switch feature/π₯
fatal: invalid reference: feature/π₯
Then pop the stash and/or do the fast and furious writing thing. Much later I would discover that I had forgotten the -c option to actually create a new branch, realizing I just messed up another unrelated branch π€¦
Obviously I need something to bring the error exit more to my attention, so I cooked up this little attention functionality
Now, when git fails, this banner pops up in the shell

Perfect π Not too noisy and and not too big, but enough to catch my attention π
Its a small function added to .zshrc. It captures the last command that was run and compare it to git (that part can of course be omitted or changed to any other program). In case of error exit from git, the banner is shown
print_error_box() {
local msg=" $1 "
local width=${#msg}
local border
border=$(printf '%*s' "$width" '')
border=${border// /β}
print -P "%F{red}β${border}β%f"
print -P "%F{red}β%f%K{red}%F{white}${msg}%f%k%F{red}β%f"
print -P "%F{red}β${border}β%f"
}
typeset -g LAST_CMD=""
preexec() {
LAST_CMD="$1"
}
precmd() {
local exit_code=$?
if (( exit_code != 0 )) && [[ "$LAST_CMD" == git* ]]; then
print_error_box "GURU MEDITATION ERROR"
fi
}
4 Comments
Anonymous · 2026-04-13 at 10:07
setopt print_exit_value
Or %? in the prompt (can use %(?..%?) to only show if non-zero)
abc · 2026-04-13 at 10:07
setopt print_exit_value
Or %? in the prompt (can use %(?..%?) to only show if non-zero)
abc · 2026-04-13 at 10:08
setopt print_exit_value
Or %? in the prompt (can use %(?..%?) to only show if non-zero)
Anthrofract · 2026-04-16 at 20:10
Jujutsu VCS fixes this
https://github.com/jj-vcs/jj