Created
January 18, 2013 23:21
-
-
Save duncanbeevers/4569536 to your computer and use it in GitHub Desktop.
PS1 hostname consistent hashing
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
# Colors | |
txtred='\[\e[0;31m\]' # Red | |
txtgrn='\[\e[0;32m\]' # Green | |
txtylw='\[\e[0;33m\]' # Yellow | |
txtblu='\[\e[0;34m\]' # Blue | |
txtpur='\[\e[0;35m\]' # Purple | |
txtcyn='\[\e[0;36m\]' # Cyan | |
bldred='\[\e[1;31m\]' # Red | |
bldgrn='\[\e[1;32m\]' # Green | |
bldylw='\[\e[1;33m\]' # Yellow | |
bldblu='\[\e[1;34m\]' # Blue | |
bldpur='\[\e[1;35m\]' # Purple | |
bldcyn='\[\e[1;36m\]' # Cyan | |
undred='\[\e[4;31m\]' # Red | |
undgrn='\[\e[4;32m\]' # Green | |
undylw='\[\e[4;33m\]' # Yellow | |
undblu='\[\e[4;34m\]' # Blue | |
undpur='\[\e[4;35m\]' # Purple | |
undcyn='\[\e[4;36m\]' # Cyan | |
txtrst='\[\e[0m\]' # Text Reset | |
hostcolors[0]=${txtred} | |
hostcolors[1]=${txtgrn} | |
hostcolors[2]=${txtylw} | |
hostcolors[3]=${txtblu} | |
hostcolors[4]=${txtpur} | |
hostcolors[5]=${txtcyn} | |
hostcolors[6]=${bldred} | |
hostcolors[7]=${bldgrn} | |
hostcolors[8]=${bldylw} | |
hostcolors[9]=${bldblu} | |
hostcolors[10]=${bldpur} | |
hostcolors[11]=${bldcyn} | |
hostcolors[12]=${undred} | |
hostcolors[13]=${undgrn} | |
hostcolors[14]=${undylw} | |
hostcolors[15]=${undblu} | |
hostcolors[16]=${undpur} | |
hostcolors[17]=${undcyn} | |
hostmd5=$(hostname | md5sum | tr -d ' -') | |
hosthex=0x${hostmd5} | |
hostmod=$((${hosthex} % 18)) | |
hostcolor=${hostcolors[${hostmod#-}]} | |
# dirname (git-branch [git-status-indicator]) $ | |
PROMPT="${txtrst}:\W \$(__git_ps1 '${txtrst}(${txtcyn}%s${txtrst}) ')${txtrst}\$ " | |
function exitstatus { | |
if [ $? -eq 0 ] | |
then | |
export PS1="${txtgrn}✓ ${hostcolor}\h$PROMPT" | |
else | |
export PS1="${txtred}× ${hostcolor}\h$PROMPT" | |
fi | |
} | |
export GIT_PS1_SHOWDIRTYSTATE='true' | |
# Preserve shell history between open shells, | |
# and collapse duplicates | |
export HISTCONTROL=erasedups | |
export HISTSIZE=10000 | |
shopt -s histappend | |
# Check last command exit status, update prompt accordingly | |
PROMPT_COMMAND='exitstatus; history -a' | |
exitstatus |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment