Skip to content

Instantly share code, notes, and snippets.

@monokrome
Created December 31, 2011 01:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monokrome/1542434 to your computer and use it in GitHub Desktop.
Save monokrome/1542434 to your computer and use it in GitHub Desktop.
My PS1
# Thanks to @kroogs for the idea of making the text red on errors :D
# This is a global reference to be used in order to know the last return
# code from within functions.
last_response_code=$?
# Formats the provided text into something a bit more striking.
error_text () { echo "\033[31m${@}\033[0m"; }
# Generates our PS1 when passed the last program's response code, and
# whatever text we want in the PS1.
make_PS1 () {
PS1_git=$(__git_ps1 "(%s) ")
if [ ${last_response_code} = 0 ]; then
echo "${PS1_git}${@} ";
else
echo -e "${PS1_git}`error_text ${@}` ";
fi
}
# A PS1.
export PS1='`last_response_code=$?;make_PS1 \W`'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment