fnm.plugin.zsh 792 B

12345678910111213141516171819202122232425262728
  1. if (( $+commands[fnm] )); then
  2. # Handle $0 according to the standard:
  3. # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
  4. 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
  5. 0="${${(M)0:#/*}:-$PWD/$0}"
  6. # remove old generated completion file
  7. command rm -f "${0:A:h}/_fnm"
  8. ver="$(fnm --version)"
  9. ver_file="$ZSH_CACHE_DIR/fnm_version"
  10. comp_file="$ZSH_CACHE_DIR/completions/_fnm"
  11. mkdir -p "${comp_file:h}"
  12. (( ${fpath[(Ie)${comp_file:h}]} )) || fpath=("${comp_file:h}" $fpath)
  13. if [[ ! -f "$comp_file" || ! -f "$ver_file" || "$ver" != "$(< "$ver_file")" ]]; then
  14. fnm completions --shell=zsh >| "$comp_file"
  15. echo "$ver" >| "$ver_file"
  16. fi
  17. declare -A _comps
  18. autoload -Uz _fnm
  19. _comps[fnm]=_fnm
  20. unset ver ver_file comp_file
  21. fi