gh.plugin.zsh 826 B

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