gh.plugin.zsh 989 B

123456789101112131415161718192021222324252627
  1. # Autocompletion for the GitHub CLI (gh).
  2. if (( ! $+commands[gh] )); then
  3. return
  4. fi
  5. # TODO: 2021-12-28: remove this block
  6. # Handle $0 according to the standard:
  7. # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
  8. 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
  9. 0="${${(M)0:#/*}:-$PWD/$0}"
  10. # Remove old generated files
  11. command rm -f "${0:A:h}/_gh" "$ZSH_CACHE_DIR/gh_version"
  12. # TODO: 2021-12-28: remove this bit of code as it exists in oh-my-zsh.sh
  13. # Add completions folder in $ZSH_CACHE_DIR
  14. command mkdir -p "$ZSH_CACHE_DIR/completions"
  15. (( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
  16. # If the completion file doesn't exist yet, we need to autoload it and
  17. # bind it to `gh`. Otherwise, compinit will have already done that.
  18. if [[ ! -f "$ZSH_CACHE_DIR/completions/_gh" ]]; then
  19. typeset -g -A _comps
  20. autoload -Uz _gh
  21. _comps[gh]=_gh
  22. fi
  23. gh completion --shell zsh >| "$ZSH_CACHE_DIR/completions/_gh" &|