#!/bin/bash

color_prompt=yes
prompt_style=randomcolors

RED="\[\e[38;5;196m\]"
WHITE="\[\e[38;5;231m\]"
MINT="\[\e[38;5;85m\]"
COOL="\[\e[38;5;81m\]"
NEON="\[\e[38;5;154m\]"
AQUA="\[\e[38;5;159m\]"
PURP="\[\e[38;5;129m\]"
GREEN="\[\e[38;5;46m\]"
PINK="\[\e[38;5;177m\]"
ORANGE="\[\e[38;5;216m\]"
BLUE="\[\e[38;5;33m\]"
PLUM="\[\e[38;5;5m\]"
CYAN="\[\e[38;5;6m\]"
RESET="\[\e[39m\]"

function randomize {
  declare -a AVAILABLE_COLORS

  AVAILABLE_COLORS=(
#    "$WHITE"
    "$RED"
    "$MINT"
    "$COOL"
    "$NEON"
    "$AQUA"
    "$PURP"
    "$GREEN"
    "$PINK"
    "$ORANGE"
    "$BLUE"
    "$PLUM"
    "$CYAN"
  )

  USER_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]} ]}
  HOST_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]} ]}
  TIME_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]} ]}
  THEME_CLOCK_COLOR=$TIME_COLOR
  PATH_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]} ]}
  TEXT_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]} ]}
  BRACKET_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]} ]}
  AT_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]} ]}
  END_COLOR=${AVAILABLE_COLORS[$RANDOM % ${#AVAILABLE_COLORS[@]} ]}

}

if [ "$color_prompt" = yes ]; then
    if [ "$prompt_style" = randomcolors ]; then
        if [[ "$USER" == "mobile" ]] || [[ "$UID" == "501" ]]; then
            randomize
            PS1="${USER_COLOR}\u${AT_COLOR}@${HOST_COLOR}\h${BRACKET_COLOR}[${PATH_COLOR}\w${BRACKET_COLOR}]${END_COLOR}$ ${TEXT_COLOR}"
        fi
        if [[ "$USER" == "root" ]] || [[ "$UID" == "0" ]]; then
            randomize
            PS1="${USER_COLOR}\u${AT_COLOR}@${HOST_COLOR}\h${BRACKET_COLOR}[${PATH_COLOR}\w${BRACKET_COLOR}]${END_COLOR}# ${TEXT_COLOR}"
        fi
    else
        if [[ "$USER" == "mobile" ]]; then
            PS1="${MINT}\u${WHITE}@${COOL}\h${WHITE}[\w]${MINT}$ ${AQUA}"
        fi
        if [[ "$USER" == "root" ]] || [[ "$UID" == "0" ]]; then
            PS1="${RED}\u${WHITE}@${COOL}\h${WHITE}[\w]${RED}# ${NEON}"
        fi
    fi
fi
