1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-15 18:30:08 +00:00

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
# Back up alias names prior to sourcing
local -a aliases_pre galiases_pre
local -A aliases_pre galiases_pre
if (( disable_aliases )); then
aliases_pre=("${(@k)aliases}")
galiases_pre=("${(@k)galiases}")
aliases_pre=("${(@kv)aliases}")
galiases_pre=("${(@kv)galiases}")
fi
# 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
if (( disable_aliases )); then
local -a disabled
# ${var:|array} gets the list of items in var not in array
disabled=("${(@k)aliases:|aliases_pre}" "${(@k)galiases:|galiases_pre}")
(( $#disabled == 0 )) || unalias "${(@)disabled}"
if (( #aliases_pre )); then
aliases=("${(@kv)aliases_pre}")
else
(( #aliases )) && unalias "${(@k)aliases}"
fi
if (( #galiases_pre )); then
galiases=("${(@kv)galiases_pre}")
else
(( #galiases )) && unalias "${(@k)galiases}"
fi
fi
}