Created
January 29, 2021 15:16
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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