#!/bin/zsh

function t_teardown {
  emulate -L zsh
  setopt local_options

  # reset current session
  ZDOTDIR=$OLD_ZDOTDIR

  # unfunction all antidote
  for fn in ${(k)functions}; do
    [[ $fn == *antidote* ]] && unfunction $fn
  done
  (( $+functions[git] )) && unfunction git

  # unfunction zsh-defer
  (( $+functions[zsh-defer] )) && unfunction zsh-defer

  # restore original fpath
  fpath=( $T_PREV_FPATH )

  # restore original zstyles
  source <(zstyle -L ':antidote:*' | awk '{print "zstyle -d",$2}')
  source <(printf '%s\n' $T_PREV_ZSTYLES)

  # remove tempdir
  [[ -d "$T_TEMPDIR" ]] && rm -rf -- "$T_TEMPDIR"
}
t_teardown "$@"
