diff --git a/plugins/gh/README.md b/plugins/gh/README.md index 54e046a1c..acf8af7f0 100644 --- a/plugins/gh/README.md +++ b/plugins/gh/README.md @@ -15,9 +15,6 @@ This plugin does not add any aliases. This plugin caches the completion script and is automatically updated when the plugin is loaded, which is usually when you start up a new terminal emulator. -The cache is stored at: - -- `$ZSH/plugins/gh/_gh` completions script - -- `$ZSH_CACHE_DIR/gh_version` version of GitHub CLI, used to invalidate - the cache. +The completion script is stored at `$ZSH_CACHE_DIR/completions/_gh`. If an +update fails, the plugin keeps the last successfully generated completion +script. diff --git a/plugins/gh/gh.plugin.zsh b/plugins/gh/gh.plugin.zsh index e7f9e347c..a1d99c1c9 100644 --- a/plugins/gh/gh.plugin.zsh +++ b/plugins/gh/gh.plugin.zsh @@ -13,6 +13,12 @@ fi zmodload -F zsh/files b:zf_mv () { - local TMPPREFIX="$ZSH_CACHE_DIR/completions/_gh" - zf_mv -f -- =( gh completion --shell zsh ) "$TMPPREFIX" + local completion_file="$ZSH_CACHE_DIR/completions/_gh" + local completion_tmp="${completion_file}.$$.${RANDOM}" + + if gh completion --shell zsh >| "$completion_tmp" && [[ -s "$completion_tmp" ]]; then + zf_mv -f -- "$completion_tmp" "$completion_file" + fi + + command rm -f -- "$completion_tmp" } &|