
prompt_jinks_help () {
  cat <<EOH
This prompt is color-scheme-able.  You can invoke it thus:

  prompt jinks [<hostname+clock-color> [<user-color> [<root-color>]]]

The default colors are green for host and green/red for user/root.
This theme works best with a dark background.

EOH
}

prompt_jinks_setup () {

  GITBRANCH=`which git 2>/dev/null`
  precmd () {
    psvar=()
    if [[ -n ${GITBRANCH} ]]; then
        BRANCH=($(git branch 2>/dev/null | grep '*')); BRANCH=$BRANCH[2]
        if [ $BRANCH ]; then
            BRANCH="(git: $BRANCH) "
            psvar[1]=$BRANCH
        fi
    fi
  }

  setopt promptsubst
  local host_col=${1:-'green'}
  local user_col=${2:-'green'}
  local root_col=${3:-'red'}
  local parens_col=blue
  colors

  PR_TITLEBAR=''
  PR_STITLE=''
  case $TERM in
  xterm*|rxvt*)
      PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | %y\a%}'
      ;;
  screen)
      PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | %y\e\\%}'
      PR_STITLE=$'%{\ekzsh\e\\%}'
      ;;
  *)
      PR_TITLEBAR=''
      ;;
  esac

  local parens="%{$fg_bold[$parens_col]%}"
  local host="%{$fg_bold[$host_col]%}"
  local usr="%{$fg_bold[$user_col]%}"
  local root="%{$fg_bold[$root_col]%}"
  local reset="%{$reset_color%}"

  local lpar="$parens($reset"
  local rpar="$parens)$reset"
  local lbra="$parens%\[$reset"
  local rbra="$parens%\]$reset"

  local clock="$lpar%{$fg_bold[$host_col]%}%T$rpar"
  local userstr="%(!.$root.$usr)%n"
  local hoststr="%{$fg_no_bold[yellow]%}@$host%m"
  local dirstr="%{$fg_bold[cyan]%}%~"
  [[ -n $SCHROOT_SESSION_ID ]] && local schroot="$lpar%{$fg_bold[red]%}${SCHROOT_SESSION_ID%%-*}$rpar"

  PS2="$lpar%{$fg_bold[cyan]%}%_$rpar%{$fg_bold[yellow]%} ->$reset "
  RPROMPT="(%B%(?.%{$fg_bold[green]%}%?.%{$fg_bold[red]%}%?)%b$reset)"
  PROMPT="$PR_STITLE${(e)PR_TITLEBAR}$schroot$clock$lbra$userstr$hoststr$rbra$dirstr$reset %v%# "

}

prompt_jinks_preview () {
  local color colors
  colors=(red yellow green blue magenta)

  if (( ! $#* )); then
    for (( i = 1; i <= $#colors; i++ )); do
      color=$colors[$i]
      prompt_preview_theme jinks $color
      (( i < $#colors )) && print
    done
  else
    prompt_preview_theme jinks "$@"
  fi
}

prompt_jinks_setup "$@"

# vim: ft=zsh:
