gh.plugin.zsh 617 B

123456789101112131415161718192021222324
  1. # Autocompletion for the GitHub CLI (gh).
  2. if (( $+commands[gh] )); then
  3. # remove old generated completion file
  4. command rm -f "${0:A:h}/_gh"
  5. ver="$(gh --version)"
  6. ver_file="$ZSH_CACHE_DIR/gh_version"
  7. comp_file="$ZSH_CACHE_DIR/completions/_gh"
  8. mkdir -p "${comp_file:h}"
  9. (( ${fpath[(Ie)${comp_file:h}]} )) || fpath=("${comp_file:h}" $fpath)
  10. if [[ ! -f "$comp_file" || ! -f "$ver_file" || "$ver" != "$(< "$ver_file")" ]]; then
  11. gh completion --shell zsh >| "$comp_file"
  12. echo "$ver" >| "$ver_file"
  13. fi
  14. declare -A _comps
  15. autoload -Uz _gh
  16. _comps[gh]=_gh
  17. unset ver ver_file comp_file
  18. fi