From: m0viefreak <m0viefreak.cm@googlemail.com>
To: zsh-workers@zsh.org
Cc: m0viefreak <m0viefreak.cm@googlemail.com>
Subject: [PATCH] completion: _arguments: behave properly when description contains '='
Date: Sun, 13 Mar 2016 23:46:46 +0100 [thread overview]
Message-ID: <1457909206-9452-1-git-send-email-m0viefreak.cm@googlemail.com> (raw)
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
reply other threads:[~2016-03-13 23:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457909206-9452-1-git-send-email-m0viefreak.cm@googlemail.com \
--to=m0viefreak.cm@googlemail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).