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

fix(cli): fix multiple errors in plugin disable/enable

This commit is contained in:
Marc Cornellà 2021-08-17 12:31:37 +02:00
parent 4455c13e06
commit 708bbe12c5
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B

View file

@ -230,9 +230,9 @@ function _omz::plugin::disable {
local awk_script=" local awk_script="
# if plugins=() is in oneline form, substitute disabled plugins and go to next line # if plugins=() is in oneline form, substitute disabled plugins and go to next line
/^\s*plugins=\([^#]+\).*\$/ { /^\s*plugins=\([^#]+\).*\$/ {
sub(/\s+(${(j:|:)dis_plugins})/, \"\") # with spaces before gsub(/\s+(${(j:|:)dis_plugins})/, \"\") # with spaces before
sub(/(${(j:|:)dis_plugins})\s+/, \"\") # with spaces after gsub(/(${(j:|:)dis_plugins})\s+/, \"\") # with spaces after
sub(/\((${(j:|:)dis_plugins})\)/, \"\") # without spaces (only plugin) gsub(/\((${(j:|:)dis_plugins})\)/, \"\") # without spaces (only plugin)
print \$0 print \$0
next 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 # if plugins=() is in multiline form, enable multi flag and disable plugins if they're there
/^\s*plugins=\(/ { /^\s*plugins=\(/ {
multi=1 multi=1
sub(/\s+(${(j:|:)dis_plugins})/, \"\") gsub(/\s+(${(j:|:)dis_plugins})/, \"\")
sub(/(${(j:|:)dis_plugins})\s+/, \"\") gsub(/(${(j:|:)dis_plugins})\s+/, \"\")
sub(/\((${(j:|:)dis_plugins})\)/, \"\") gsub(/\((${(j:|:)dis_plugins})\)/, \"\")
print \$0 print \$0
next next
} }
@ -251,17 +251,17 @@ function _omz::plugin::disable {
# add new plugins and disable multi flag # add new plugins and disable multi flag
multi == 1 && /^[^#]*\)/ { multi == 1 && /^[^#]*\)/ {
multi=0 multi=0
sub(/\s+(${(j:|:)dis_plugins})/, \"\") gsub(/\s+(${(j:|:)dis_plugins})/, \"\")
sub(/(${(j:|:)dis_plugins})\s+/, \"\") gsub(/(${(j:|:)dis_plugins})\s+/, \"\")
sub(/\((${(j:|:)dis_plugins})\)/, \"\") gsub(/\((${(j:|:)dis_plugins})\)/, \"\")
print \$0 print \$0
next next
} }
multi == 1 { multi == 1 {
sub(/\s+(${(j:|:)dis_plugins})/, \"\") gsub(/\s+(${(j:|:)dis_plugins})/, \"\")
sub(/(${(j:|:)dis_plugins})\s+/, \"\") gsub(/(${(j:|:)dis_plugins})\s+/, \"\")
sub(/\((${(j:|:)dis_plugins})\)/, \"\") gsub(/\((${(j:|:)dis_plugins})\)/, \"\")
print \$0 print \$0
next next
} }
@ -283,13 +283,13 @@ multi == 1 {
# Exit if the new .zshrc file has syntax errors # Exit if the new .zshrc file has syntax errors
if ! zsh -n ~/.zshrc; then if ! zsh -n ~/.zshrc; then
_omz::log error "broken syntax in ~/.zshrc. Rolling back changes..." _omz::log error "broken syntax in ~/.zshrc. Rolling back changes..."
mv ~/.zshrc ~/.zshrc.disabled command mv -f ~/.zshrc ~/.zshrc.disabled
mv ~/.zshrc.swp ~/.zshrc command mv -f ~/.zshrc.swp ~/.zshrc
return 1 return 1
fi fi
# Restart the zsh session if there were no errors # 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 # Old zsh versions don't have ZSH_ARGZERO
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}" local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
@ -344,26 +344,27 @@ multi == 1 && /^[^#]*\)/ {
{ print \$0 } { print \$0 }
" "
awk "$awk_script" ~/.zshrc > ~/.zshrc.disabled \ awk "$awk_script" ~/.zshrc > ~/.zshrc.enabled \
&& mv ~/.zshrc ~/.zshrc.swp \ && command mv -f ~/.zshrc ~/.zshrc.swp \
&& mv ~/.zshrc.disabled ~/.zshrc && command mv -f ~/.zshrc.enabled ~/.zshrc
# Exit if the new .zshrc file wasn't created correctly # Exit if the new .zshrc file wasn't created correctly
[[ $? -eq 0 ]] || { [[ $? -eq 0 ]] || {
local ret=$? local ret=$?
_omz::log error "error disabling plugins." _omz::log error "error enabling plugins."
return $ret return $ret
} }
# Exit if the new .zshrc file has syntax errors # Exit if the new .zshrc file has syntax errors
if ! zsh -n ~/.zshrc; then if ! zsh -n ~/.zshrc; then
_omz::log error "broken syntax in ~/.zshrc. Rolling back changes..." _omz::log error "broken syntax in ~/.zshrc. Rolling back changes..."
mv ~/.zshrc ~/.zshrc.disabled command mv -f ~/.zshrc ~/.zshrc.enabled
mv ~/.zshrc.swp ~/.zshrc command mv -f ~/.zshrc.swp ~/.zshrc
return 1 return 1
fi fi
# Restart the zsh session if there were no errors # 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 # Old zsh versions don't have ZSH_ARGZERO
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}" local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"