# emulate -L zsh
# setopt local_options extended_glob

# zsh_comp_refresh() {
  ZSH_CACHE_DIR="${XDG_CACHE_HOME:-${HOME%/}/.cache}"'/zsh'
  ZSH_COMPDUMP="${HOME%/}"'/.cache/zsh/zcompdump'

  if command -p -- test "${ZSH_COMPDUMP-}" = '' || {
    command -p -- test ! "${ZSH_COMPDUMP-}" != "${ZSH_COMPDUMP#*'zcompdump-'}" &&
      command -p -- test ! "${ZSH_COMPDUMP-}" != "${ZSH_COMPDUMP#*'zcompdump.'}"
  }; then

    while command -p -- test "$(
      command find -- "${ZSH_CACHE_DIR-}" \
        -xdev \
        -path '*/.git' -prune -o \
        -path '*/Library' -prune -o \
        -path "${ZSH_CACHE_DIR}"'/*/*' -prune -o \
        -name 'zcompdump*' \
        -type f \
        -print
    )" != ''; do
      command find -- "${ZSH_CACHE_DIR}" \
        -xdev \
        -path '*/.git' -prune -o \
        -path '*/Library' -prune -o \
        -path "${ZSH_CACHE_DIR}"'/*/*' -prune -o \
        -name 'zcompdump*' \
        -type f \
        -exec sh -c 'command -p -- rm -f -- "${1-}"' _ {} ';'
    done
  fi

  # [ -d $_comp_path:h ] || mkdir -p $_comp_path:h
  # rm -f "${_comp_path}"
  # autoload -Uz compinit  && compinit -d "$_comp_path"
  # compinit -d "$_comp_path"
  # unset -v -- _comp_path
  # exec ${SHELL} -l
# }

# zsh_cache_build() {
#   for filename in $(command find "${ZDOTDIR}" -L -name "*.zsh" -type f); do
#     zcompile $filename
#   done
# }

# zsh_cache_clear() {
#   for filename in $(command find "${ZDOTDIR}" -L -name "*.zwc" -type f); do
#     command rm -f $filename
#   done
# }

# zsh_cache_clear() {
#   findprint="-print"
#   finddel="-delete"
#   # if [[ "$1" == '-q' ]]; then
#   #   findprint=""
#   # elif [[ "$1" == "--dry-run" ]]; then
#   #   finddel=""
#   # fi

#   if [[ -d "${ZDOTDIR}" ]]; then
#     find "${ZDOTDIR:A}" -type f \( -name "*.zwc" -o -name "*.zwc.old" \) $findprint $finddel
#   fi
#   find "$HOME" -maxdepth 1 -type f \( -name "*.zwc" -o -name "*.zwc.old" \) $findprint $finddel
#   find . -maxdepth 1 -type f \( -name "*.zwc" -o -name "*.zwc.old" \) $findprint $finddel
#   find "$HOME/.cache/zsh" -maxdepth 1 -type f \( -name "*.zwc" -o -name "*.zwc.old" \) $findprint $finddel
#   unset findargs
# }

# zsh_cache_clear
# # zsh_cache_build
# zsh_comp_refresh
