* [PATCH] completion: _arguments: behave properly when description contains '='
@ 2016-03-13 22:46 m0viefreak
0 siblings, 0 replies; only message in thread
From: m0viefreak @ 2016-03-13 22:46 UTC (permalink / raw)
To: zsh-workers; +Cc: m0viefreak
In some cases wrong options were generated. Example:
command --help output:
--foo use with --bar=baz
In this case it would wrongly interpret the option as taking arguments:
--foo=[use with --bar=baz]:--foo
After parsing the --help output, zsh internally stores that option as
--foo:some option (useful with --bar=baz)
Later it filters the options using the following:
tmp=("${(@M)lopts:##$~pattern(|:*)}")
The (|:*) part is supposed to be limiting the matching to the part
before the ':'. This does however not work at all.
It will simply use the empty variant and match anyways.
Fix:
- Instead of (|:*) only use :* so that it can't fall back to the
empty variant.
- For that to work a : must be added even if the option has no
description.
- In this case, remove the appended : after the filtering.
- When checking for = and [= arguments, change the pattern
#*\[\=*}" to #[^:]##\[\=*}"
to make sure the matching occurs in front of the :
Now the completion above correctly creates
--foo[use with --bar=baz]
---
Completion/Base/Utility/_arguments | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/Completion/Base/Utility/_arguments b/Completion/Base/Utility/_arguments
index 687c0c4..82c9696 100644
--- a/Completion/Base/Utility/_arguments
+++ b/Completion/Base/Utility/_arguments
@@ -105,7 +105,10 @@ if (( long )); then
continue
else
# Still no comment, add the previous options anyway.
- lopts+=("${tmp[@]}")
+ # Add a ':' after the option anyways, to make the the matching of
+ # the options lateron work as intended.
+ # It will be removed again later.
+ lopts+=("${^tmp[@]}":)
tmp=()
fi
fi
@@ -147,7 +150,7 @@ if (( long )); then
done
# Tidy up any remaining uncommented options.
if (( ${#tmp} )); then
- lopts+=("${tmp[@]}")
+ lopts+=("${^tmp[@]}":)
fi
# Remove options also described by user-defined specs.
@@ -220,19 +223,22 @@ if (( long )); then
# Ignore :descriptions at the ends of lopts for matching this;
# they aren't in the patterns.
- tmp=("${(@M)lopts:##$~pattern(|:*)}")
- lopts=("${(@)lopts:##$~pattern(|:*)}")
+ tmp=("${(@M)lopts:##$~pattern:*}")
+ lopts=("${(@)lopts:##$~pattern:*}")
(( $#tmp )) || continue
opt=''
+ # Clean suffix ':' added earlier
+ tmp=("${(@)tmp%:}")
+
# If there are option strings with a `[=', we take these to get an
# optional argument.
- tmpo=("${(@M)tmp:#*\[\=*}")
+ tmpo=("${(@M)tmp:#[^:]##\[\=*}")
if (( $#tmpo )); then
- tmp=("${(@)tmp:#*\[\=*}")
+ tmp=("${(@)tmp:#[^:]##\[\=*}")
for opt in "$tmpo[@]"; do
# Look for --option:description and turn it into
@@ -263,9 +269,9 @@ if (( long )); then
# Basically the same as the foregoing.
# TODO: could they be combined?
- tmpo=("${(@M)tmp:#*\=*}")
+ tmpo=("${(@M)tmp:#[^:]##\=*}")
if (( $#tmpo )); then
- tmp=("${(@)tmp:#*\=*}")
+ tmp=("${(@)tmp:#[^:]##\=*}")
for opt in "$tmpo[@]"; do
if [[ $opt = (#b)(*):([^:]#) ]]; then
--
2.5.0.234.gefc8a62
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-03-13 23:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-13 22:46 [PATCH] completion: _arguments: behave properly when description contains '=' m0viefreak
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).