From a28ce8bc9955196c0f06fb043a039c378d273c9c Mon Sep 17 00:00:00 2001 From: mrsauravsahu Date: Sun, 6 Sep 2026 19:49:03 +0530 Subject: [PATCH] Fix: load completions when zcompdump is missing The compinit cache check used `[[ -n ${dump}(#qN.mh+24) ]]`. With EXTENDED_GLOB set the qualifier does match, so fresh and stale dumps were routed correctly, but a *missing* dump also produced an empty match and fell to the `compinit -C` branch. `-C` skips the dump rebuild entirely, so a first run on a new machine, or any run after the dump was deleted, came up with no completions loaded and stayed that way until the file happened to reappear. Match through an array and invert the condition so the fast path is taken only on a positive match: fresh (<24h) -> compinit -C stale (>24h) -> compinit + touch missing -> compinit + touch Also pass -d explicitly so both branches agree on the dump path, and save and restore EXTENDED_GLOB instead of unconditionally unsetting an option the user's own config may have enabled. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_017opPVGYfryqcV8BAt66zqW --- src/scripts/setup.programs-conf.zsh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/scripts/setup.programs-conf.zsh b/src/scripts/setup.programs-conf.zsh index 1376e6e..84afa7a 100755 --- a/src/scripts/setup.programs-conf.zsh +++ b/src/scripts/setup.programs-conf.zsh @@ -6,19 +6,26 @@ echo >>$CLI_CONFIG_PROGRAMS_CONF echo '# init all cli-config tools' >>$CLI_CONFIG_PROGRAMS_CONF { echo 'autoload -Uz compinit' - echo 'setopt extendedglob' + echo '# Glob qualifiers need EXTENDED_GLOB. Remember the prior state and restore it,' + echo '# rather than unconditionally clearing an option the user may rely on.' + echo '_cli_config_eg=0; [[ -o extendedglob ]] || { _cli_config_eg=1; setopt extendedglob }' echo '_cli_config_zcompdump=${ZDOTDIR:-$HOME}/.zcompdump' - echo 'if [[ -n ${_cli_config_zcompdump}(#qN.mh+24) ]]; then' - echo ' compinit' + echo '# The previous [[ -n path(#qN.mh+24) ]] form took the -C branch when the dump was' + echo '# MISSING as well as when it was fresh, so a first run (or a deleted dump) loaded' + echo '# no completions at all. Match through an array instead: (#qN.mh-24) yields the' + echo '# dump only if it exists, is a plain file, and is less than 24h old.' + echo '_cli_config_zcompdump_fresh=( ${_cli_config_zcompdump}(#qN.mh-24) )' + echo 'if (( $#_cli_config_zcompdump_fresh )); then' + echo ' compinit -C -d ${_cli_config_zcompdump}' + echo 'else' + echo ' compinit -d ${_cli_config_zcompdump}' echo ' # compinit only rewrites the dump when completions actually changed, so its' echo ' # mtime can stay stale forever - touch it so the 24h check resets and the' echo ' # next start takes the fast -C path.' echo ' touch ${_cli_config_zcompdump}' - echo 'else' - echo ' compinit -C' echo 'fi' - echo 'unset _cli_config_zcompdump' - echo 'unsetopt extendedglob' + echo '(( _cli_config_eg )) && unsetopt extendedglob' + echo 'unset _cli_config_zcompdump _cli_config_zcompdump_fresh _cli_config_eg' } >>$CLI_CONFIG_PROGRAMS_CONF # plugin manager must be sourced first so lazyload is available to other confs