Created
December 31, 2011 01:50
-
-
Save monokrome/1542434 to your computer and use it in GitHub Desktop.
My PS1
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
# 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