Skip to content

Instantly share code, notes, and snippets.

@mbbx6spp
Last active December 17, 2015 14:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mbbx6spp/5622645 to your computer and use it in GitHub Desktop.
Save mbbx6spp/5622645 to your computer and use it in GitHub Desktop.
Add this to your .bash_profile to handle history properly across multiple terminals, and output exit code of last command plus suitable fortune in appropriate color.
declare -r red=$'\e[31;40m'
declare -r blue=$'\e[0;34m'
declare -r d=$'\e[37;40m' # set this to what makes sense for your terminal color scheme
shopt -s histappend
pre_prompt() {
local exit_code=$?;
history -a;
history -n;
if [ ${exit_code} -eq 0 ]; then
local msg="OK"
echo "${blue}?=${exit_code} | ${msg}${d}";
else
# -o means offensive. Not for the faint of heart or those that pair or screenshare a lot!
local msg=$(fortune -o -s -n 140)
echo "${red}?=${exit_code} | ${msg}${d}";
fi;
}
export PROMPT_COMMAND=pre_prompt
export HISTCONTROL=ignoredups:ignorespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment