Skip to content

Instantly share code, notes, and snippets.

@blackjack
Last active September 29, 2015 15:15
Show Gist options
  • Save blackjack/8c8620533f05d6c9838b to your computer and use it in GitHub Desktop.
Save blackjack/8c8620533f05d6c9838b to your computer and use it in GitHub Desktop.
Colored prompt for bash
reset_color="\[\033[00m\]"
color_code=$(( 104 + (16#$(hostname | md5sum | cut -c 10) % 127) ))
host_color="\[\033[38;05;${color_code}m\]"
user_color="\[\033[1;32m\]"
path_color="\[\033[1;33m\]"
prompt_sign="\$"
if [ ${UID} -eq 0 ]; then
user_color="\[\033[1;31m\]"
path_color="\[\033[1;31m\]"
prompt_sign="\#"
fi
PS1=$(echo -ne "[$user_color\u$reset_color@$host_color\h$reset_color $path_color\w$reset_color]$prompt_sign ")
root_color=$'%{\e[1;31m%}'
user_color=$'%{\e[1;32m%}'
path_color=$'%{\e[1;33m%}'
fg_normal=$'%{\e[033;0m%}'
host_color_code=$(( 104 + (16#$(hostname | md5sum | cut -c 8 ) % 127) ))
host_color=$(echo -e "%{\e[38;05;${host_color_code}m%}")
PS1="[%(!.$root_color.$user_color)%n$fg_normal@$host_color%m$fg_normal %(!,$root_color,$path_color)%~$fg_normal%\]%(!,#,%%) "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment