Skip to content

Instantly share code, notes, and snippets.

@andiogenes
Created June 26, 2025 09:25
Show Gist options
  • Save andiogenes/c101ec50d07258084d5504117741ed82 to your computer and use it in GitHub Desktop.
Save andiogenes/c101ec50d07258084d5504117741ed82 to your computer and use it in GitHub Desktop.
oh-my-zsh prompt with exit code on the right side of line and background jobs count on the left
ZSH_THEME="robbyrussell"
# https://zenbro.github.io/2015/07/23/show-exit-code-of-last-command-in-zsh.html
function check_last_exit_code() {
local LAST_EXIT_CODE=$?
if [[ $LAST_EXIT_CODE -ne 0 ]]; then
local EXIT_CODE_PROMPT=' '
EXIT_CODE_PROMPT+="%{$fg[red]%}%{$reset_color%}"
EXIT_CODE_PROMPT+="%{$fg_bold[red]%}$LAST_EXIT_CODE%{$reset_color%}"
EXIT_CODE_PROMPT+="%{$fg[red]%}%{$reset_color%}"
echo "$EXIT_CODE_PROMPT"
fi
}
RPROMPT='$(check_last_exit_code)'
# https://blog.pabuisson.com/2023/11/show-background-jobs-in-zsh-prompt/
PROMPT='%(1j.%{$fg_bold[yellow]%}[%j]%{$reset_color%} .)'$PROMPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment