# This is sort of hacky and not sure why it's necessary
# I assumed ~/.zshenv is utilized for all systems but this may not be true?
# Need to investigate when I have time
if [ -z "$TMUX_TMPDIR" ]; then
    source $HOME/.zshenv
fi

# load custom executable functions
for function in "$ZDOTDIR"/functions/*; do
  source $function
done

# extra files in $ZDOTDIR/configs/pre , $ZDOTDIR/configs , and $ZDOTDIR/configs/post
# these are loaded first, second, and third, respectively.
_load_settings() {
  _dir="$1"
  if [ -d "$_dir" ]; then
    if [ -d "$_dir/pre" ]; then
      for config in "$_dir"/pre/**/*~*.zwc(N-.); do
        . $config
      done
    fi

    for config in "$_dir"/**/*(N-.); do
      case "$config" in
        "$_dir"/(pre|post)/*|*.zwc)
          :
          ;;
        *)
          . $config
          ;;
      esac
    done

    if [ -d "$_dir/post" ]; then
      for config in "$_dir"/post/**/*~*.zwc(N-.); do
        . $config
      done
    fi
  fi
}
_load_settings "$ZDOTDIR/configs"

declare -A hostname_colors

# Load local override configs
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local

#
# PROMPT
# I'd like to move this into it's own file but am having issues with the git branch extrapolating correctly
#
if [ ! -z "${VIMRUNTIME}" ]; then
    PROMPT_PRE="%F{yellow}[VIM SHELL] "
fi

HOSTNAME_COLOR="${HOSTNAME_COLOR:={{ .hostname_color }}}"
PROMPT="${PROMPT_PRE:=}%F{blue}%n%f@%F{$HOSTNAME_COLOR}%m%f:%F{cyan}%~%f [%F{214}%*%f] \$vcs_info_msg_0_%(?.%F{green}:).%F{red}:()%f"$' ${PROMPT_POST:=}\n'"|--%# "

# The following is to configure git branch info
# Git branch appears on right side of prompt, where available
autoload -Uz vcs_info
precmd_vcs_info() { vcs_info }
precmd_functions+=( precmd_vcs_info )
setopt prompt_subst
zstyle ':vcs_info:git:*' formats '%F{5}(%b)%f '
zstyle ':vcs_info:*' enable git
