Make options.zsh nounset-resilient #164
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR: Make zgenom options.zsh nounset-resilient (setopt -u)
Summary
This document tracks the upstream PR preparation to harden
zgenom'soptions.zshagainstsetopt -u(nounset) without changing behavior in normal environments.$ZDOTDIR/.zqs-zgenom(fresh clone).zqs-zgenom/options.zshfix/nounset-resilience-optionsWhy this change
Several patterns in the original
options.zshexpand variables that may be unset during early init phases. Withsetopt -uin effect, those expansions cause hard errors:[[ -z "${VAR}" ]]checks that expand unset variables${(t)_comps}to detectcompinithaving runWhat changed (techniques)
No functional behavior change; only parameter expansion safety.
Numeric compares use arithmetic defaults:
[[ $ZGENOM_AUTO_ADD_BIN -eq 1 ]](( ${ZGENOM_AUTO_ADD_BIN:-0} == 1 ))Empty/existence checks avoid expanding unset:
[[ -z "${VAR}" ]][[ -z ${VAR-} ]]or(( ${+VAR} == 0 ))Compinit detection uses existence test instead of type expansion:
[[ -z "${(t)_comps}" ]](( ${+_comps} == 0 ))Defaults/derived values guarded without expanding parents:
: ${ZGEN_CUSTOM_COMPDUMP:=${ZGEN_DIR}/zcompdump_${ZSH_VERSION}}(only whenZGEN_DIRis set)Initialize arrays/scalars with safe idioms:
: ${ARR:=()}: ${SCALAR:=default}Preserve quoting semantics where the original used
${(q)...}when building flags.Patch highlights (excerpts)
How to test locally (zsh startup)
Use both a forced zgenom regeneration and a normal startup. Look for any “parameter not set” or aborts.
ZDOTDIR="$HOME/dotfiles/dot-config/zsh" ZSH_FORCE_ZGEN_RESET=1 zsh -iZDOTDIR="$HOME/dotfiles/dot-config/zsh" zsh -iparameter not setmessages fromoptions.zshNote: We do not purposely force
set -uglobally during init; the goal is resilience if a user enables it in their environment.Upstream PR steps
Using GitHub CLI (newer versions don’t have
--yesforgh repo fork):If not using
gh, open the compare URL in a browser:Compatibility and risk
Status
.zqs-zgenom/options.zsh