Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] completion: _arguments: behave properly when description contains '='
- X-seq: zsh-workers 38153
- From: m0viefreak <m0viefreak.cm@xxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH] completion: _arguments: behave properly when description contains '='
- Date: Sun, 13 Mar 2016 23:46:46 +0100
- Cc: m0viefreak <m0viefreak.cm@xxxxxxxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=jrd4MVsF00qUyNWonnbXHyf1vPRJ9Vd4OF3kGphnZ24=; b=iMWI7B6IBxFP6oQF7U9vtogwlGGLQGBvynN0xGit+FLVewkugMhOYKS1ppc6WkNQYQ lUFhxkyqE7igHQ9MLxu1Wh8NgE4bmFai5ijmK6x0++v8or7E6LIERABHYvNUYm4LhDy8 ZOib78wePfAQ3xHo4o/fLd00gMpT4S8SMnqYGNrt3070NQwrq5a9KuRfo8jkwyf9Rk5k WtEYGzc9Im5qplSkRnGkOplMvYq5YMvMW0NxBKLd/itZDbYXwsqiDjbZHohmcVUOdEqJ tuHLVgNHLmuALRMb51K9/AU2QQEa09yAo+t/pGEX+zZYssBRe8vPTdAqoO+LBi8E3Pg7 HBIA==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author