From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: use new splitting mechanism for _sequence
Date: Sun, 12 Oct 2014 00:22:50 +0200 [thread overview]
Message-ID: <13376.1413066170@thecus.kiddle.eu> (raw)
This changes _sequence to use the new way of splitting strings with
a dynamic separator from 33423.
The patch also adds some quoting to cope with separators that need to be
quoted.
Oliver
diff --git a/Completion/Base/Utility/_sequence b/Completion/Base/Utility/_sequence
index 391e5f7..9167b8f 100644
--- a/Completion/Base/Utility/_sequence
+++ b/Completion/Base/Utility/_sequence
@@ -7,11 +7,11 @@
# -s sep : specify separator [defaults to comma]
# -d : duplicate values allowed
-local curcontext="$curcontext" nm="$compstate[nmatches]" pre nosep minus
+local curcontext="$curcontext" nm="$compstate[nmatches]" pre qsep nosep minus
local -a sep num pref suf end uniq dedup
zparseopts -D -a opts s:=sep n:=num p:=pref i:=pref P:=pref I:=suf S:=suf q=suf r:=suf R:=suf C:=cont d=uniq M: J: X: x:
-(( $#cont )) && curcontext="$curcontext%:*}:$cont[2]"
+(( $#cont )) && curcontext="${curcontext%:*}:$cont[2]"
(( $#sep )) || sep[2]=,
if (( $+suf[(r)-S] )); then
@@ -19,20 +19,20 @@ if (( $+suf[(r)-S] )); then
(( $#end )) && compset -S ${end}\* && suf=() && nosep=1
fi
+qsep="${sep[2]}"
+compquote -p qsep
if (( ! $#uniq )); then
(( $+pref[(r)-P] )) && pre="${(q)pref[pref[(i)-P]+1]}"
- typeset -T unique="${PREFIX#$pre}" uniq $sep[2]
- dedup=( ${(q)uniq[1,-2]} )
- unique="${SUFFIX}"
- dedup+=( ${(q)uniq[2,-1]} )
+ dedup=( "${(@)${(@ps.$qsep.)PREFIX#$pre}[1,-2]}" "${(@)${(@ps.$qsep.)SUFFIX}[2,-1]}" )
+ [[ -n $compstate[quoting] ]] || dedup=( ${(Q)dedup} )
fi
-if (( ! $#num )) || (( num[2] > 1 )) && ! compset -P $(( num[2] - 1 )) \*$sep[2]; then
- (( nosep )) || suf=( -S $sep[2] -r "$end[1]${sep[2][1]} \t\n\-" )
- compset -S ${sep[2]}\* && suf=()
- compset -P \*$sep[2] && pref=()
-else
+if (( $#num )) && compset -P $(( num[2] - 1 )) \*${(q)qsep}; then
pref=()
+else
+ (( ! nosep && (!$#num || num[2] > 1) )) && suf=( -S ${qsep} -r "$end[1]${(q)qsep[1]} \t\n\-" )
+ compset -S ${(q)qsep}\* && suf=()
+ compset -P \*${(q)qsep} && pref=()
fi
(( minus = argv[(ib:2:)-] ))
reply other threads:[~2014-10-11 22:30 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=13376.1413066170@thecus.kiddle.eu \
--to=okiddle@yahoo.co.uk \
--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).