From b20d95c3900721b2cbbe0f8f60e631a7347d0aea Mon Sep 17 00:00:00 2001 From: Robby Russell Date: Thu, 10 Sep 2026 05:33:39 -0700 Subject: [PATCH] fix(gh): preserve valid completion cache on failure --- plugins/gh/README.md | 2 ++ plugins/gh/gh.plugin.zsh | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) 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" } &|