Last active
December 17, 2015 14:09
-
-
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.
This file contains 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
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