summaryrefslogtreecommitdiff
path: root/plugins/gh/gh.plugin.zsh
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2021-09-27 13:03:58 -0600
committerTuowen Zhao <ztuowen@gmail.com>2021-09-27 13:03:58 -0600
commitc674485e6b4abe313469900997d893d2940ee843 (patch)
treed6ca6edaff3d81849489f31ca13b127acef89c75 /plugins/gh/gh.plugin.zsh
parent3c73976ef306d68a85d60c94be9a1dcdc33fa2bf (diff)
parent93ad3a88214b95f571e03c21f7d9bd76f9110938 (diff)
downloadzsh-c674485e6b4abe313469900997d893d2940ee843.tar.gz
zsh-c674485e6b4abe313469900997d893d2940ee843.tar.bz2
zsh-c674485e6b4abe313469900997d893d2940ee843.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'plugins/gh/gh.plugin.zsh')
-rw-r--r--plugins/gh/gh.plugin.zsh23
1 files changed, 17 insertions, 6 deletions
diff --git a/plugins/gh/gh.plugin.zsh b/plugins/gh/gh.plugin.zsh
index 8e055ec35..3e4cdee5e 100644
--- a/plugins/gh/gh.plugin.zsh
+++ b/plugins/gh/gh.plugin.zsh
@@ -1,13 +1,24 @@
# Autocompletion for the GitHub CLI (gh).
-
if (( $+commands[gh] )); then
- if [[ ! -r "$ZSH_CACHE_DIR/gh_version" \
- || "$(gh --version)" != "$(< "$ZSH_CACHE_DIR/gh_version")"
- || ! -f "$ZSH/plugins/gh/_gh" ]]; then
- gh completion --shell zsh > $ZSH/plugins/gh/_gh
- gh --version > $ZSH_CACHE_DIR/gh_version
+ # remove old generated completion file
+ command rm -f "${0:A:h}/_gh"
+
+ ver="$(gh --version)"
+ ver_file="$ZSH_CACHE_DIR/gh_version"
+ comp_file="$ZSH_CACHE_DIR/completions/_gh"
+
+ mkdir -p "${comp_file:h}"
+ (( ${fpath[(Ie)${comp_file:h}]} )) || fpath=("${comp_file:h}" $fpath)
+
+ if [[ ! -f "$comp_file" || ! -f "$ver_file" || "$ver" != "$(< "$ver_file")" ]]; then
+ gh completion --shell zsh >| "$comp_file"
+ echo "$ver" >| "$ver_file"
fi
+
+ declare -A _comps
autoload -Uz _gh
_comps[gh]=_gh
+
+ unset ver ver_file comp_file
fi