#!/bin/zsh

### Setup antidote.
#function antidote-setup {
  0=${(%):-%x}
  typeset -gH ANTIDOTE_ZSH="${0:a:h:h}/antidote.zsh"

  fpath=( "${0:A:h}" $fpath )
  local fn
  for fn in ${0:A:h}/*; do
    [[ ${fn:t} != 'antidote-setup' ]] || continue
    if typeset -f ${fn:t} > /dev/null; then
      unfunction -- ${fn:t}
    fi

    # autoload extensionless function files
    [[ -z "${fn:e}" ]] && autoload -Uz "${fn}"
  done

  # man pages
  if [[ "$MANPATH" != *"${0:A:h:h}/man"* ]]; then
    export MANPATH="${0:A:h:h}/man:$MANPATH"
  fi

  builtin autoload -Uz is-at-least
  if is-at-least 5.8; then
    # -D : Delete flags from the param array once they are detected
    # -M : Map a flag to alternative names (useful for defining -s(hort) and --long options)
    # -F : Fail if a flag is provided that was not defined in the zparseopts spec
    # the -F option was added in 5.8
    typeset -gHa _adote_zparopt_flags=( -D -M -F )
  else
    typeset -gHa _adote_zparopt_flags=( -D -M )
  fi

  typeset -gHi __adote_ksh_arrays
  typeset -gHi __adote_sh_glob
#}
