#!/usr/bin/env bash

# Reset colors:
RESET=$(tput sgr0)
# Erase to end of line:
ERASE=$(tput el || tput ce)

#-------------------------------------------------------------------------------

function background() {
  local colors
  local color
  colors=(92 93 57 21 27 33 39 45 51 50 49 48 47 46 82 118 154 190 226 220 214 208 202 196)
  color=$((RANDOM % colors))
  tput setab "$color"
}

#-------------------------------------------------------------------------------

# https://github.com/mhulse/dotfizzles/issues/213
source "/usr/local/opt/git/etc/bash_completion.d/git-prompt.sh"

# Unstaged (*) and staged (+) changes will be shown next to the branch name.
GIT_PS1_SHOWDIRTYSTATE=1

# If something is stashed, then a '$' will be shown next to the branch name.
GIT_PS1_SHOWSTASHSTATE=1

# If there're untracked files, then a '%' will be shown next to the branch name.
GIT_PS1_SHOWUNTRACKEDFILES=1

# See the difference between HEAD and its upstream.
# A "<" indicates you are behind, ">" indicates you are ahead, "<>" indicates
# you have diverged and "=" indicates that there is no difference.
GIT_PS1_SHOWUPSTREAM=("auto" "verbose" "name")

# See more information about the identity of commits.
GIT_PS1_DESCRIBE_STYLE="default"

# Colored hint about the current dirty state.
GIT_PS1_SHOWCOLORHINTS=1

#-------------------------------------------------------------------------------

printf "%s" \
  "$RESET" \
  "$(background)" \
  "\w" \
  "$(__git_ps1)" \
  "$ERASE" \
  "$RESET" \
  "\n" \
  "▌"