gh.plugin.zsh 544 B

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