Skip to content

Instantly share code, notes, and snippets.

@floer32
Created May 9, 2013 16:43
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 floer32/5548699 to your computer and use it in GitHub Desktop.
Save floer32/5548699 to your computer and use it in GitHub Desktop.
Tiny colored prompt. I don't love it, but I've been using it for a while anyways. Best feature is that it is colorized based on the exit status of the previous command.
#########################################
## Prompt stylization and history sync ##
#########################################
bash_prompt_command() {
# Grab exit status of previous command
RTN=$?
prevCmd=$(prevCmd $RTN)
# Save and reload the history after each command finishes
history -a; history -c; history -r;
} # bash_prompt_command()
export PROMPT_COMMAND=bash_prompt_command
prevCmd () {
if [ $1 == 0 ] ; then
echo $GREEN
else
echo $RED
fi
}
if [ $(tput colors) -gt 0 ] ; then
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
RST=$(tput op)
fi
export PS1="\[\e[36m\]\u:\W\[\e[0m\]\[\$prevCmd\]>\[$RST\]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment