#!/bin/zsh
zmodload -Fa zsh/files b:zf_mv b:zf_mkdir
zmodload -F zsh/parameter p:commands p:dirstack p:functions

${0}:precmd() {
  setopt autopushd pushdignoredups  # Set *global* shell options.
  builtin autoload -Uz chpwd_recent_dirs chpwd_recent_filehandler

  local __=
  builtin zstyle -s :chpwd: recent-dirs-file __ ||
      builtin zstyle ':chpwd:*' recent-dirs-file \
          ${XDG_DATA_HOME:-$HOME/.local/share}/zsh/chpwd-recent-dirs
  builtin zstyle -s :chpwd: recent-dirs-max __ ||
      builtin zstyle ':chpwd:*' recent-dirs-max 0

  local -a reply=()
  chpwd_recent_filehandler
  dirstack=( "$reply[@]" )

  add-zsh-hook chpwd chpwd_recent_dirs
}
