# Produces a nice, colorful 2-line prompt of the form:
# [username@hostname:current_directory] (git_repo|branch)
# $
#
# You can add the output of arbitrary env vars with something like this:
# ${C_RED}\$(echo -n \$ENV_VAR_NAME)${C_NO}

src_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $src_dir/colorize.sh

function sp_git {
  # Get the current branch name
  local git_branch=$(git branch 2>/dev/null | grep "*" | cut -d ' ' -f 2) || ""

  # If we're in a git repo, add the repo (i.e. top-level directory) name, and parens
  if [ "$git_branch" != "" ]; then
    local git_repo=$(git rev-parse --show-toplevel)
    git_repo=${git_repo//*\/}
    echo "(${git_repo}|${git_branch})"
  fi
}

function sp_path {
  local git_dir=$(git rev-parse --show-toplevel 2>/dev/null)
  if [ "$git_dir" != "" ]; then
    local path=${PWD//$git_dir/\!}
  else
    local path=${PWD//$HOME/\~}
  fi
  echo $path
}

function sp_docker_context {
  local name=$(docker context inspect | grep Name | tr -d ' ' | sed -E "s/\"Name\":\"(.*)\",/\1/")
  [ $name != 'default' ] && echo $name
}

export PS1="[${C_YELLOW}\u${C_NO}@${C_BLUE}${HOSTNAME}${C_NO}:${C_GREEN}\$(sp_path)${C_NO}] ${C_MAGENTA}\$(sp_git)${C_NO} ${C_GREEN}\$(sp_docker_context)${C_NO} ${C_RED}\$(echo -n \$DOCKER_MACHINE_NAME)${C_NO} \n${C_RED}\$ ${C_NO}"