# colors color_green='\[\e[1;32;40m\]' color_blue='\[\e[1;34;40m\]' color_magenta='\[\e[1;35;40m\]' color_cyan='\[\e[1;36;40m\]' color_white='\[\e[1;37;40m\]' color_yellow='\[\e[1;33;40m\]' color_red='\[\e[1;31;40m\]' color_black='\[\e[1;37;40m\]' color_reset='\[\e[0m\]' # random color set_random_color () { # \[, \e, and \] would need extra escaping, so for clarity we return only the color code case $((RANDOM%8+1)) in 1 ) color='[30;1m';; 2 ) color='[31;1m';; 3 ) color='[32;1m';; 4 ) color='[33;1m';; 5 ) color='[34;1m';; 6 ) color='[35;1m';; 7 ) color='[36;1m';; 8 ) color='[37;1m';; esac printf $color } color_random='\[\e$(set_random_color)\]' # variable color, depending on whether we are root, sudo'd as a user, or simply us set_user_color() { # \[, \e, and \] would need extra escaping, so for clarity we return only the color code red='[31;1m' white='[37;1m' reset='[0m' if [[ $EUID -eq 0 ]]; then echo $red elif [[ -n $SUDO_USER ]]; then echo $white else printf $reset fi } user_color='\[\e$(set_user_color)\]' # colored components user_and_host=${color_random}'\u'${color_random}'@'${color_random}'\h' # user@host working_dir=${color_random}:'\w ' # current working directory got_root=${color_random}'\$' # do we have root? $ or # cmd_num=${color_random}['\#'] # command number time_clock=${color_random}['\T'] # command number # gather the pieces together to set the bash prompt: visible_prompt="${cmd_num}${time_clock} ${user_and_host}${working_dir}${got_root} ${color_random}" export PS1="${visible_prompt}" # end of bash prompt config