fix(init): avoid overwriting existing aliases

Fix regression introduced in #11550. If an existing alias was present in
the moment of sourcing, and oh-my-zsh aliases were disabled for that
file, it'd be overwritten aswell. See #11658.
This commit is contained in:
Carlo Sala 2023-05-01 22:21:01 +02:00
parent 2e7a247cab
commit b22593cf17

View file

@ -159,10 +159,10 @@ _omz_source() {
zstyle -T ":omz:${context}" aliases || disable_aliases=1 zstyle -T ":omz:${context}" aliases || disable_aliases=1
# Back up alias names prior to sourcing # Back up alias names prior to sourcing
local -a aliases_pre galiases_pre local -A aliases_pre galiases_pre
if (( disable_aliases )); then if (( disable_aliases )); then
aliases_pre=("${(@k)aliases}") aliases_pre=("${(@kv)aliases}")
galiases_pre=("${(@k)galiases}") galiases_pre=("${(@kv)galiases}")
fi fi
# Source file from $ZSH_CUSTOM if it exists, otherwise from $ZSH # Source file from $ZSH_CUSTOM if it exists, otherwise from $ZSH
@ -174,10 +174,16 @@ _omz_source() {
# Unset all aliases that don't appear in the backed up list of aliases # Unset all aliases that don't appear in the backed up list of aliases
if (( disable_aliases )); then if (( disable_aliases )); then
local -a disabled if (( #aliases_pre )); then
# ${var:|array} gets the list of items in var not in array aliases=("${(@kv)aliases_pre}")
disabled=("${(@k)aliases:|aliases_pre}" "${(@k)galiases:|galiases_pre}") else
(( $#disabled == 0 )) || unalias "${(@)disabled}" (( #aliases )) && unalias "${(@k)aliases}"
fi
if (( #galiases_pre )); then
galiases=("${(@kv)galiases_pre}")
else
(( #galiases )) && unalias "${(@k)galiases}"
fi
fi fi
} }