Skip to content

Instantly share code, notes, and snippets.

@iamludal
Created January 29, 2021 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamludal/d5cadf4cecb148dbe2dd7f9439fe8679 to your computer and use it in GitHub Desktop.
Save iamludal/d5cadf4cecb148dbe2dd7f9439fe8679 to your computer and use it in GitHub Desktop.
Display the status code of the last executed command. Add this snippet to your .bashrc or .zshrc file.
col_success="$(tput setaf 10)"
col_failure="$(tput setaf 9)"
col_normal="$(tput sgr0)"
col_fade="$(tput setaf 15)"
function _prompt_() {
local code="$?"
if [ "$code" -ne 0 ];
then
if [ "$code" -gt 128 -a "$code" -le 192 ]
then # Failure or Signal
echo -n "${col_fade}[${col_failure}${code}${col_normal}/${col_failure}"
echo -n $(kill -l "${code}" | tr '[:upper:]' '[:lower:]')
echo "${col_fade}]${col_normal}"
else # Failure
echo "${col_fade}[${col_failure}${code}${col_fade}]${col_normal}"
fi
else # No error
echo "${col_fade}[${col_success}${code}${col_fade}]${col_normal}"
fi
}
PROMPT_COMMAND="_prompt_"
col_success="$(tput setaf 10)"
col_failure="$(tput setaf 9)"
col_normal="$(tput sgr0)"
col_fade="$(tput setaf 15)"
function precmd() {
local code="$?"
if [ "$code" -ne 0 ];
then
if [ "$code" -gt 128 -a "$code" -le 192 ]
then # Failure or Signal
echo -n "${col_fade}[${col_failure}${code}${col_normal}/${col_failure}"
echo -n $(kill -l "${code}" | tr '[:upper:]' '[:lower:]')
echo "${col_fade}]${col_normal}"
else # Failure
echo "${col_fade}[${col_failure}${code}${col_fade}]${col_normal}"
fi
else # No error
echo "${col_fade}[${col_success}${code}${col_fade}]${col_normal}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment