Make zsh-quickstart-kit ZDOTDIR-aware and nounset-resilient #312
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 zsh-quickstart-kit ZDOTDIR-aware and nounset-resilient
This change makes core zsh-quickstart-kit files work seamlessly when users set ZDOTDIR to a custom configuration directory, and hardens them against
setopt nounset
(error on unset parameters).Summary of changes
Files modified:
~/...
paths to zsh config files with${ZDOTDIR:-$HOME}/...
${VAR-}
,${VAR:-default}
,(( ${+VAR} ))
)~/.zqs-zprof-enabled
,~/.zqs-debug-mode
,~/.zqs-settings-path
,~/.zqs-settings
~/.zshrc.pre-plugins.d
,~/.zshrc.add-plugins.d
,~/.zshrc.d
,~/.zshrc.$(uname).d
,~/.zshrc.work.d
~/.zgen-setup
,~/.zsh_functions
,~/.zsh_aliases
,~/.sh_aliases
~/.zsh/completions
cache path,~/.zsh-completions(.d)
~/.macos_aliases(.d)
,~/.osx_aliases(.d)
~/.zsh_history
,~/.zsh-quickstart-last-update
,~/.p10k.zsh
[[ -z "$LSCOLORS" ]]
->[[ -z ${LSCOLORS-} ]]
[[ -z "$SSH_CLIENT" ]]
->[[ -z ${SSH_CLIENT-} ]]
[[ -z "$GENCOMPL_PY" ]]
->[[ -z ${GENCOMPL_PY-} ]]
[[ -n "$ZSH_COMPLETION_HACK" ]]
->[[ -n ${ZSH_COMPLETION_HACK-} ]]
[[ -z "$TREE_IGNORE" ]]
->[[ -z ${TREE_IGNORE-} ]]
[[ -n "$GOPATH" ]]
->[[ -n ${GOPATH-} ]]
[[ -n "$DESK_ENV" ]]
->[[ -n ${DESK_ENV-} ]]
load-shell-fragments
now guards$1
with${1-}
and properly quotes pathsZGEN_DIR=${ZGEN_DIR:-${ZDOTDIR:-$HOME}/.zgenom}
${ZDOTDIR:-$HOME}
for prompt change marker, additional-plugins, OMZ gating, plugin directories, and zgen init timestamps.zgen-local-plugins
,.zsh-quickstart-local-plugins
${ZDOTDIR:-$HOME}/.zsh/complete
)need_update
if (( ${+EDITOR} )); then export VISUAL="$EDITOR"; fi
${ZDOTDIR:-$HOME}/.zsh_aliases.local
instead of~/.zsh_aliases.local
${ZDOTDIR:-$HOME}/.zsh_functions.local
instead of~/.zsh_functions.local
Behavior when ZDOTDIR is unset remains identical because
${ZDOTDIR:-$HOME}
falls back to$HOME
.Rationale
$XDG_CONFIG_HOME/zsh
)$HOME
when ZDOTDIR is unsetHow to test
Test matrix:
$HOME
)Common setup:
.zshrc
is a symlink to the kit’szsh/.zshrc
(as recommended by zqs docs)A) ZDOTDIR set
ZDOTDIR="$HOME/dotfiles/dot-config/zsh" ZSH_FORCE_ZGEN_RESET=1 zsh -i -c exit
ZDOTDIR="$HOME/dotfiles/dot-config/zsh" zsh -i -c exit
parameter not set
errors${ZDOTDIR}/.zsh_history
${ZDOTDIR}/.zsh/cache
.zgenom/init.zsh
created under${ZDOTDIR}/.zgenom/
B) ZDOTDIR unset
$HOME
:env -u ZDOTDIR ZSH_FORCE_ZGEN_RESET=1 zsh -i -c exit
env -u ZDOTDIR zsh -i -c exit
$HOME
instead of${ZDOTDIR}
Smoke checks in both scenarios:
zqs update-plugins
(via zgenom)zqs check-for-updates
(last-update stamp is at${ZDOTDIR}/.zsh-quickstart-last-update
)~/.zqs-zprof-enabled
in the active ZDOTDIR and confirm zprof loads/suppressesSuggested branch name and commit message
fix/zdotdir-nounset-resilience
Make zsh-quickstart-kit ZDOTDIR-aware and nounset-resilient
Open the PR upstream
From the kit checkout directory (the repo that contains
zsh/.zshrc
):git checkout -b fix/zdotdir-nounset-resilience
git add zsh/.zshrc zsh/.zgen-setup zsh/.zsh_aliases zsh/.zsh_functions
git commit -m "Make zsh-quickstart-kit ZDOTDIR-aware and nounset-resilient\n\n- Use \${ZDOTDIR:-$HOME} for config paths\n- Guard unset vars with \${VAR-}/\${VAR:-default}/(( \${+VAR} ))\n- Preserve behavior when ZDOTDIR unset"
gh repo fork --remote --remote-name fork
git push -u fork fix/zdotdir-nounset-resilience
gh pr create --base main --head <your-user>:fix/zdotdir-nounset-resilience \ --title "Make zsh-quickstart-kit ZDOTDIR-aware and nounset-resilient" \ --body "See description and test plan in the PR. Maintains backward compatibility when ZDOTDIR is unset."
Manual alternative:
https://github.com/unixorn/zsh-quickstart-kit/compare/main...<your-user>:fix/zdotdir-nounset-resilience?expand=1
Notes
~/.ssh
,~/.aws
) intentionally left under$HOME
.