From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] prevent parameters leaking from various completers
Date: Wed, 03 Jan 2018 18:00:08 +0100 [thread overview]
Message-ID: <13713.1514998808@thecus.kiddle.eu> (raw)
In-Reply-To: <20171226021740.81700-1-llua@gmx.com>
On 25 Dec, Eric Cook wrote:
> +++ b/Completion/Unix/Command/_yp
> +local curcontext="$curcontext" line state expl ret=1 _yp_cache_nicks _yp_args
> if (( ! $+_yp_cache_maps )); then
In this particular case, the use of a global variable as a cache was
intentional and the change actually breaks _yp completion.
Adding typeset -g makes the intention rather clearer. I also would
prefer _cache_ as the initial prefix on any such variable making it
easier to unset them en masse.
Caching _yp_args is fairly pointless. ypwhich is also fairly instant so
I'm not sure we gain much by caching that either but perhaps it
generates network traffic to the NIS master so I'll leave it for now. It
probably was slow enough in 2001 to justify the caching.
Oliver
PS. This reminds me that I was supposed to cleanup the caching
mechanism. I won't, however, have much time for a few weeks.
diff --git a/Completion/Unix/Command/_yp b/Completion/Unix/Command/_yp
index b7619a02e..efd9aae5f 100644
--- a/Completion/Unix/Command/_yp
+++ b/Completion/Unix/Command/_yp
@@ -1,25 +1,27 @@
#compdef ypcat ypmatch yppasswd ypwhich ypset ypserv ypbind yppush yppoll ypxfr domainname
-local curcontext="$curcontext" line state expl ret=1 _yp_cache_nicks _yp_args
+local curcontext="$curcontext" line state expl args ret=1
typeset -A opt_args
-if (( ! $+_yp_cache_maps )); then
- _yp_cache_maps=( "${(@)${(@f)$(_call_program maps ypwhich -m)}%% *}" )
- _yp_cache_nicks=( "${(@)${(@)${(@f)$(_call_program names ypwhich -x)}#*\"}%%\"*}" )
- _yp_args=(
- '(-x)-d[specify domain]:domain name' \
- '(-x)-k[display keys]' \
- '(-x)-t[inhibit nicknames]' \
- '(: -d -k -t)-x[display nicknames]' \
- )
+if (( ! $+_cache_yp_maps )); then
+ typeset -ga _cache_yp_maps _cache_yp_nicks
+ _cache_yp_maps=( "${(@)${(@f)$(_call_program maps ypwhich -m)}%% *}" )
+ _cache_yp_nicks=( "${(@)${(@)${(@f)$(_call_program names ypwhich -x)}#*\"}%%\"*}" )
fi
+args=(
+ '(-x)-d[specify domain]:domain name' \
+ '(-x)-k[display keys]' \
+ '(-x)-t[inhibit nicknames]' \
+ '(: -d -k -t)-x[display nicknames]' \
+)
+
case "$service" in
ypcat)
- _arguments -C -s "$_yp_args[@]" ':map name:->map' && ret=0
+ _arguments -C -s $args ':map name:->map' && ret=0
;;
ypmatch)
- _arguments -C -s "$_yp_args[@]" '::key map:->keymap' ':map name:->map' &&
+ _arguments -C -s $args '::key map:->keymap' ':map name:->map' &&
ret=0
;;
yppasswd)
@@ -96,9 +98,9 @@ if [[ "$state" = map* ]]; then
# The `-M ...' allows `pa.n<TAB>' to complete to `passwd.byname'.
_requested maps expl 'map name' \
compadd -M 'l:.|by=by l:.|=by r:|.=* r:|=*' -a \
- _yp_cache_maps && ret=0
+ _cache_yp_maps && ret=0
_requested nicknames expl nicknames \
- compadd -a _yp_cache_nicks && ret=0
+ compadd -a _cache_yp_nicks && ret=0
(( ret )) || return 0
done
elif [[ "$state" = servers ]]; then
next prev parent reply other threads:[~2018-01-03 17:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-26 2:17 Eric Cook
2018-01-03 17:00 ` Oliver Kiddle [this message]
2018-01-04 14:07 ` Eric Cook
2018-01-06 6:43 ` dana
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=13713.1514998808@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).