autoload -Uz promptinit && promptinit

if [[ "$TERM" == (dumb|linux|*bsd*) ]] || (( $#prompt_argv < 1 )); then
  prompt 'off'
fi

#
# ZLE widgets
#

function zle-line-init zle-keymap-select {

    # Couldn't figure out how to get tmux and iTerm to agree on how to render
    # these characters... so there you go.

    local normal_symbol="N"
    local insert_symbol="I"
    local error_symbol="X"

    # Show vi status / return status on the right side

    local return_status="%{%F{red}%}%(?.. $error_symbol)%{$reset_color%}"
    if [ $KEYMAP = 'vicmd' ]; then
      local edit_status="%{%F{cyan}%}$normal_symbol"
    else
      local edit_status="%{%F{green}%}$insert_symbol"
    fi

    RPROMPT="${edit_status}${return_status}%{$reset_color%}"
    zle reset-prompt
}
zle -N zle-line-init
zle -N zle-keymap-select

#
# Setup Prompt
#

function prompt_setup {
  setopt LOCAL_OPTIONS
  unsetopt XTRACE KSH_ARRAYS
  prompt_opts=(cr percent subst)

  # Load required functions.
  autoload -Uz add-zsh-hook

  # Define prompts.
  PROMPT='
%{%F{black}%}$(env_info) $(node_info) $(rust_info) $(python_info)
%{%F{magenta}%}%n%{%f%}@%{%F{yellow}%}$(hostname -s)%{%f%} %{%B%F{green}%}${PWD/#$HOME/~}%{%f%b%}$(git_info)%{%f%}
%(?,,%{${%B%F{white}%}[%?]%{%f%b%} )%% '
}

prompt_setup "$@"
setopt PROMPT_SUBST
setopt PROMPT_PERCENT
setopt TRANSIENT_RPROMPT