From b22593cf179bae479ab32700c5a7b94d3053762d Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Mon, 1 May 2023 22:21:01 +0200 Subject: [PATCH] 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. --- oh-my-zsh.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index e047d4834..a577c1f41 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -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 }