Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Ohmyzsh
Commits
bf888680
Unverified
Commit
bf888680
authored
Aug 17, 2021
by
Marc Cornellà
Browse files
refactor(cli): extract substitution awk script in `plugin disable`
parent
708bbe12
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/cli.zsh
View file @
bf888680
...
@@ -226,13 +226,17 @@ function _omz::plugin::disable {
...
@@ -226,13 +226,17 @@ function _omz::plugin::disable {
return
1
return
1
fi
fi
# Remove plugins substitution awk script
local
awk_subst_plugins
=
"
\
gsub(/
\s
+(
${
(j
:|:
)dis_plugins
}
)/,
\"\"
) # with spaces before
gsub(/(
${
(j
:|:
)dis_plugins
}
)
\s
+/,
\"\"
) # with spaces after
gsub(/
\(
(
${
(j
:|:
)dis_plugins
}
)
\)
/,
\"\"
) # without spaces (only plugin)
"
# Disable plugins awk script
# Disable plugins awk script
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=
\(
[^#]+
\)
.*
\$
/ {
gsub(/
\s
+(
${
(j
:|:
)dis_plugins
}
)/,
\"\"
) # with spaces before
$awk_subst_plugins
gsub(/(
${
(j
:|:
)dis_plugins
}
)
\s
+/,
\"\"
) # with spaces after
gsub(/
\(
(
${
(j
:|:
)dis_plugins
}
)
\)
/,
\"\"
) # without spaces (only plugin)
print
\$
0
print
\$
0
next
next
}
}
...
@@ -240,29 +244,22 @@ function _omz::plugin::disable {
...
@@ -240,29 +244,22 @@ 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
gsub(/
\s
+(
${
(j
:|:
)dis_plugins
}
)/,
\"\"
)
$awk_subst_plugins
gsub(/(
${
(j
:|:
)dis_plugins
}
)
\s
+/,
\"\"
)
gsub(/
\(
(
${
(j
:|:
)dis_plugins
}
)
\)
/,
\"\"
)
print
\$
0
print
\$
0
next
next
}
}
# if multi flag is enabled and we find a valid closing parenthesis,
# if multi flag is enabled and we find a valid closing parenthesis, remove plugins and disable multi flag
# add new plugins and disable multi flag
multi == 1 && /^[^#]*
\)
/ {
multi == 1 && /^[^#]*
\)
/ {
multi=0
multi=0
gsub(/
\s
+(
${
(j
:|:
)dis_plugins
}
)/,
\"\"
)
$awk_subst_plugins
gsub(/(
${
(j
:|:
)dis_plugins
}
)
\s
+/,
\"\"
)
gsub(/
\(
(
${
(j
:|:
)dis_plugins
}
)
\)
/,
\"\"
)
print
\$
0
print
\$
0
next
next
}
}
multi == 1 {
multi == 1 && length(
\$
0) > 0 {
gsub(/
\s
+(
${
(j
:|:
)dis_plugins
}
)/,
\"\"
)
$awk_subst_plugins
gsub(/(
${
(j
:|:
)dis_plugins
}
)
\s
+/,
\"\"
)
if (length(
\$
0) > 0) print
\$
0
gsub(/
\(
(
${
(j
:|:
)dis_plugins
}
)
\)
/,
\"\"
)
print
\$
0
next
next
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment