Skip to content

Commit

Permalink
fix(init): avoid overwriting existing aliases
Browse files Browse the repository at this point in the history
Fix regression introduced in ohmyzsh#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 ohmyzsh#11658.
  • Loading branch information
carlosala authored and Gabor Garami committed May 2, 2023
1 parent 8d06173 commit 270f63f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions oh-my-zsh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit 270f63f

Please sign in to comment.