Skip to content

Instantly share code, notes, and snippets.

@craSH
Created April 24, 2010 07:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craSH/377513 to your computer and use it in GitHub Desktop.
Save craSH/377513 to your computer and use it in GitHub Desktop.
color your prompt based roughly (1/8*2 hashing) on hostname -f output. Also strip vowels from hostname to give a shorter prompt.
if [ "$PS1" ]; then
if [ "$BASH" ]; then
shortname=${HOSTNAME%%.*}
shortname=${shortname//[aeiou]/}
hostname_crc=$(echo $HOSTNAME | tr 'A-Z' 'a-z' | cksum)
hostname_crc=${hostname_crc%% *}
hostcolor_a=$(( (0x${hostname_crc} + 1) % 2 ))
hostcolor_b=$(( 0x${hostname_crc} % 8 + 30 ))
PS1="\[\e[33;1m\]\u@\[\e[${hostcolor_a};${hostcolor_b}m\]${shortname}:\[\e[0m\]\w"'\$ '
PS2='\[\e[31;1m\]>\[\e[0m\]'
unset shortname hostname_crc hostcolor_a hostcolor_b
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi
export PS1
export PS2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment