fix(git): handle nounset option in prompt variable checks

When `set -u` (nounset) is enabled, referencing ${RPROMPT}
and ${RPS1}-${RPS4} without a parameter expansion default
causes shell errors because these variables may not be set.

Add `-` to parameter expansions to provide an empty default
when variables are unset, matching the existing handling of
${PS1}-${PS4} which are always set by zsh.

Fixes #13701
This commit is contained in:
御风 2026-06-14 10:30:24 +08:00
parent 5181447da8
commit 65c3b59fcc

View File

@ -162,13 +162,13 @@ if zstyle -t ':omz:alpha:lib:git' async-prompt \
# or any of the other prompt variables
function _defer_async_git_register() {
# Check if git_prompt_info is used in a prompt variable
case "${PS1}:${PS2}:${PS3}:${PS4}:${RPROMPT}:${RPS1}:${RPS2}:${RPS3}:${RPS4}" in
case "${PS1}:${PS2}:${PS3}:${PS4}:${RPROMPT-}:${RPS1-}:${RPS2-}:${RPS3-}:${RPS4-}" in
*(\$\(git_prompt_info\)|\`git_prompt_info\`)*)
_omz_register_handler _omz_git_prompt_info
;;
esac
case "${PS1}:${PS2}:${PS3}:${PS4}:${RPROMPT}:${RPS1}:${RPS2}:${RPS3}:${RPS4}" in
case "${PS1}:${PS2}:${PS3}:${PS4}:${RPROMPT-}:${RPS1-}:${RPS2-}:${RPS3-}:${RPS4-}" in
*(\$\(git_prompt_status\)|\`git_prompt_status\`)*)
_omz_register_handler _omz_git_prompt_status
;;