diff --git a/plugins/gh/README.md b/plugins/gh/README.md index 1de7242a3..cc399ef83 100644 --- a/plugins/gh/README.md +++ b/plugins/gh/README.md @@ -18,3 +18,5 @@ plugin is loaded, which is usually when you start up a new terminal emulator. The cache is stored at: - `$ZSH_CACHE_DIR/completions/_gh` completions script + +If an update fails, the last successfully generated completion script is kept. 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" } &|