#!/bin/bash

color_prompt=yes
prompt_style=randomcolors

RED="%F{196}"
WHITE="%F{231}"
MINT="%F{085}"
COOL="%F{081}"
NEON="%F{154}"
AQUA="%F{159}"
PURP="%F{129}"
GREEN="%F{046}"
PINK="%F{177}"
ORANGE="%F{216}"
BLUE="%F{033}"
PLUM="%F{005}"
CYAN="%F{006}"
RESET="%F{reset}"

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}%n${AT_COLOR}@${HOST_COLOR}%m${BRACKET_COLOR}[${PATH_COLOR}%(4~|.../%2~|%~)${BRACKET_COLOR}]${END_COLOR}$ ${TEXT_COLOR}"
        fi
        if [[ "$USER" == "root" ]] || [[ "$UID" == "0" ]]; then
            randomize
            PS1="${USER_COLOR}%n${AT_COLOR}@${HOST_COLOR}%m${BRACKET_COLOR}[${PATH_COLOR}%(4~|.../%2~|%~)${BRACKET_COLOR}]${END_COLOR}# ${TEXT_COLOR}"
        fi
    else
        if [[ "$USER" == "mobile" ]]; then
            PS1="${MINT}%n${WHITE}@${COOL}%m${WHITE}[%(4~|.../%2~|%~)]${MINT}$ ${reset}"
        fi
        if [[ "$USER" == "root" ]] || [[ "$UID" == "0" ]]; then
            PS1="${RED}%n${WHITE}@${COOL}%m${WHITE}[%(4~|.../%2~|%~)]${RED}# ${reset}"
        fi
    fi
fi
