writing your own terminal prompt

autoload -Uz vcs_info
autoload -U colors && colors
SUCCESS_EMOJIS=("🙆‍♀️" "💁‍♀️" "🙋‍♀️")
FAILURE_EMOJIS=("🙅‍♀️" "🤦‍♀️" "🤷‍♀️")

setopt prompt_subst
setopt PROMPT_SUBST
zstyle ':vcs_info:git:*' check_for_changes true
zstyle ':vcs_info:git:*' check_for_staged_changes true
zstyle ':vcs_info:git:*' formats ":%s(%b)"

precmd() {
  myprompt
}

function myprompt() {
  RETVAL=$?
  vcs_info

  local 'STATUS_COLOR' 'PROMPTMOJI'
  if [[ $RETVAL -eq 0 ]]; then
    STATUS_COLOR=green
    SIZE=${#SUCCESS_EMOJIS[@]}
    INDEX=$(($RANDOM % $SIZE))
    PROMPTMOJI="${SUCCESS_EMOJIS[$INDEX + 1]}"
  else
    STATUS_COLOR=red
    SIZE=${#FAILURE_EMOJIS[@]}
    INDEX=$(($RANDOM % $SIZE))
    PROMPTMOJI="${FAILURE_EMOJIS[$INDEX + 1]}"
  fi

  if [ $FASTPROMPT ]; then
    PS1=%F{blue}%~' '"🏃‍♀️"$'\n'%F{$STATUS_COLOR}'↳ '%f
    return
  fi

  local 'TF_VERSION_PROMPT'
  if [ -e .terraform-version ]; then
    TF_VERSION_PROMPT="using %F{magenta}tf$(tfenv version-name)%f "
  else
    TF_VERSION_PROMPT=""
  fi

  local 'AWS_PROMPT'
  if [ -z $AWS_PROFILE ]; then
    AWS_PROMPT=""
  else
    AWS_PROMPT="on %F{yellow}$AWS_PROFILE%f "
  fi

  if kubectl config current-context &> /dev/null ; then
    KUBE_CONTEXT_PROMPT="on %F{cyan}$(kubectl config current-context)($(kubens -c))%f "
  else
    KUBE_CONTEXT_PROMPT=""
  fi

  PS1=%F{blue}%~%f%F{green}${vcs_info_msg_0_}%f' '"$AWS_PROMPT""$TF_VERSION_PROMPT""$KUBE_CONTEXT_PROMPT""$PROMPTMOJI"$'\n'%F{$STATUS_COLOR}'↳ '%f
  # PS0=$'\nps0'
  # PS2="ps2 > "
  return
}

alias fastprompt="export FASTPROMPT=true"
alias slowprompt="unset FASTPROMPT"