Created
April 24, 2010 07:02
-
-
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.
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
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