#!/usr/bin/env bash


prompt_git_and_status() {
	local ps1_exit=$?
	local s='';
	local branchName='';

  if [ $ps1_exit -eq 0 ]; then
    ps1_status="${3}"
  else
    ps1_status="${4}"
  fi

	# Check if the current directory is in a Git repository.
	if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}") == '0' ]; then

		dirty=$(git diff --quiet --ignore-submodules HEAD &>/dev/null; [ $? -eq 1 ]&& echo -e "*")
		branchName=`git symbolic-ref -q --short HEAD`

		printf "%s" "${1}${branchName}${2}${dirty} "
	fi;
  printf "%s" "${ps1_status}\$"
}

# Set the terminal title to the current working directory.
PS1="\[\033]0;\W\007\]"; # working directory base name
#PS1+="\[${bold}\]";
#PS1+="\[${userStyle}\]\u"; # username
#PS1+="\[${white}\]@";
#PS1+="\[${hostStyle}\]\h"; # host
#PS1+="\[${white}\] : ";
PS1+="\[${green}\]\w"; # working directory full path
PS1+="\$(prompt_git_and_status \"\[${white}\] on \[${violet}\]\" \"\[${blue}\]\" \"\[${white}\]\" \"\[${red}\]\")"; # Git repository details and $
PS1+=" \[${reset}\]"; # and reset color
export PS1;

PS2="\[${yellow}\]→ \[${reset}\]";
export PS2;

# hack: fix slow startup of mc
alias mc="PS1= PROMPT_COMMAND= mc"
