From 708bbe12c5817e380c83d0c49bf684b0fc5d0024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 17 Aug 2021 12:31:37 +0200 Subject: [PATCH] fix(cli): fix multiple errors in `plugin disable/enable` --- lib/cli.zsh | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index 1289df730..e490149e0 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -230,9 +230,9 @@ function _omz::plugin::disable { local awk_script=" # if plugins=() is in oneline form, substitute disabled plugins and go to next line /^\s*plugins=\([^#]+\).*\$/ { - sub(/\s+(${(j:|:)dis_plugins})/, \"\") # with spaces before - sub(/(${(j:|:)dis_plugins})\s+/, \"\") # with spaces after - sub(/\((${(j:|:)dis_plugins})\)/, \"\") # without spaces (only plugin) + gsub(/\s+(${(j:|:)dis_plugins})/, \"\") # with spaces before + gsub(/(${(j:|:)dis_plugins})\s+/, \"\") # with spaces after + gsub(/\((${(j:|:)dis_plugins})\)/, \"\") # without spaces (only plugin) print \$0 next } @@ -240,9 +240,9 @@ function _omz::plugin::disable { # if plugins=() is in multiline form, enable multi flag and disable plugins if they're there /^\s*plugins=\(/ { multi=1 - sub(/\s+(${(j:|:)dis_plugins})/, \"\") - sub(/(${(j:|:)dis_plugins})\s+/, \"\") - sub(/\((${(j:|:)dis_plugins})\)/, \"\") + gsub(/\s+(${(j:|:)dis_plugins})/, \"\") + gsub(/(${(j:|:)dis_plugins})\s+/, \"\") + gsub(/\((${(j:|:)dis_plugins})\)/, \"\") print \$0 next } @@ -251,17 +251,17 @@ function _omz::plugin::disable { # add new plugins and disable multi flag multi == 1 && /^[^#]*\)/ { multi=0 - sub(/\s+(${(j:|:)dis_plugins})/, \"\") - sub(/(${(j:|:)dis_plugins})\s+/, \"\") - sub(/\((${(j:|:)dis_plugins})\)/, \"\") + gsub(/\s+(${(j:|:)dis_plugins})/, \"\") + gsub(/(${(j:|:)dis_plugins})\s+/, \"\") + gsub(/\((${(j:|:)dis_plugins})\)/, \"\") print \$0 next } multi == 1 { - sub(/\s+(${(j:|:)dis_plugins})/, \"\") - sub(/(${(j:|:)dis_plugins})\s+/, \"\") - sub(/\((${(j:|:)dis_plugins})\)/, \"\") + gsub(/\s+(${(j:|:)dis_plugins})/, \"\") + gsub(/(${(j:|:)dis_plugins})\s+/, \"\") + gsub(/\((${(j:|:)dis_plugins})\)/, \"\") print \$0 next } @@ -283,13 +283,13 @@ multi == 1 { # Exit if the new .zshrc file has syntax errors if ! zsh -n ~/.zshrc; then _omz::log error "broken syntax in ~/.zshrc. Rolling back changes..." - mv ~/.zshrc ~/.zshrc.disabled - mv ~/.zshrc.swp ~/.zshrc + command mv -f ~/.zshrc ~/.zshrc.disabled + command mv -f ~/.zshrc.swp ~/.zshrc return 1 fi # Restart the zsh session if there were no errors - _omz::log info "" + _omz::log info "plugins disabled: ${(j:, :)dis_plugins}." # Old zsh versions don't have ZSH_ARGZERO local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}" @@ -344,26 +344,27 @@ multi == 1 && /^[^#]*\)/ { { print \$0 } " - awk "$awk_script" ~/.zshrc > ~/.zshrc.disabled \ - && mv ~/.zshrc ~/.zshrc.swp \ - && mv ~/.zshrc.disabled ~/.zshrc + awk "$awk_script" ~/.zshrc > ~/.zshrc.enabled \ + && command mv -f ~/.zshrc ~/.zshrc.swp \ + && command mv -f ~/.zshrc.enabled ~/.zshrc # Exit if the new .zshrc file wasn't created correctly [[ $? -eq 0 ]] || { local ret=$? - _omz::log error "error disabling plugins." + _omz::log error "error enabling plugins." return $ret } # Exit if the new .zshrc file has syntax errors if ! zsh -n ~/.zshrc; then _omz::log error "broken syntax in ~/.zshrc. Rolling back changes..." - mv ~/.zshrc ~/.zshrc.disabled - mv ~/.zshrc.swp ~/.zshrc + command mv -f ~/.zshrc ~/.zshrc.enabled + command mv -f ~/.zshrc.swp ~/.zshrc return 1 fi # Restart the zsh session if there were no errors + _omz::log info "plugins enabled: ${(j:, :)add_plugins}." # Old zsh versions don't have ZSH_ARGZERO local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"