Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] prevent parameters leaking from various completers
- X-seq: zsh-workers 42208
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: [PATCH] prevent parameters leaking from various completers
- Date: Wed, 03 Jan 2018 18:00:08 +0100
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1515000057; bh=pJdW7tA3XTXerkl56hNups0jJUGjlfEFDXUeU6KbGy4=; h=From:References:To:Subject:Date:From:Subject; b=JjIcpsDExs8mx4dArAeN8H54U+zRuyPdW+FI9mEigcj5QsOJPxKraEhF6uta1lv7qHEJ0e7zq3wZqkEDdRhghIRD5P+3FaHaA/ifiJDkcgH08KiB+Cvq/Z2NAQqUkqKGzccZeSHl6QivK7hC6kf1IQckjgGPn4KjMFAIGUfbuNZuvcxtipl25wJ2zqXSwOTt+pJzQo5LFTmpGUlBonujXhfHBj8AQcgCgK+s3NW6xCeLbVDhj5EWwG2cX35VnmE1yieJNaZY2jzJBL452ODkJpduDNrVQik0ijqXWpFGEix62DvvYO1UsB4TiQVt1UsBC8DotcCvrzbMSzLEJ5hrXg==
- In-reply-to: <20171226021740.81700-1-llua@gmx.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author