Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] _gpg: Use explicit UIDs for state = public keys.
- X-seq: zsh-workers 42972
- From: Doron Behar <doron.behar@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: [PATCH] _gpg: Use explicit UIDs for state = public keys.
- Date: Sat, 9 Jun 2018 21:59:42 +0300
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=tlNvBVtR6qOvqdjp5L7eyG52o+ChmsbC3wo+kRtiG3w=; b=ElB5XoHSJAjgv3qd5u3S4ftmxnFFVsQM2Fp7Wb/sERrWFDLtjdIVyRav2aglSAXT8b pqfZYK0CGsfOczBYsIsXDPqzLbd3FFC0eL+5HMDQKYWuEo9qv4H0JmBk/FttlWCDgQfV d+GrPD2AMGroxUxoH5GER3fDorcRaB1uPCdE2gRXVjBTBFleamffRINEazNhhFnSNaDs 4jg5HFYm8Tba4eB7HudYuT8z5l1NtGTwg1YlZ9348x5z+/2nAsU/dQXYAftPpb9FLdiz ls6gYZhnBV140dxZoJYxKj2WfkkhtzHmi/82d82BG8NX8y0KydTlLuWTyEfbbgo59hWt bAwQ==
- In-reply-to: <20180609182155.arzktjvvvtnlm57k@tarpaulin.shahaf.local2>
- 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>
- Mail-followup-to: zsh-workers@xxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20180607144857.8835-1-doron.behar@gmail.com> <20180609182155.arzktjvvvtnlm57k@tarpaulin.shahaf.local2>
On Sat, Jun 09, 2018 at 06:21:55PM +0000, Daniel Shahaf wrote:
> doron.behar@xxxxxxxxx wrote on Thu, Jun 07, 2018 at 17:48:57 +0300:
> > Use the `--with-colons` option in conjunction with `(f)` and `(@s.:.)`
> > to parse the output.
> > Quote the variables used in `_call_program`.
> > ---
> > Completion/Unix/Command/_gpg | 71 ++++++++++++++++++++++++++++++++----
> > 1 file changed, 64 insertions(+), 7 deletions(-)
> >
> > diff --git a/Completion/Unix/Command/_gpg b/Completion/Unix/Command/_gpg
> > index 48a36eff2..a09ba3f9e 100644
> > --- a/Completion/Unix/Command/_gpg
> > +++ b/Completion/Unix/Command/_gpg
> > @@ -206,20 +206,77 @@ fi
> >
> > case "$state" in
> > public-keys)
> > - _wanted public-keys expl 'public key' \
> > - compadd ${${(Mo)$(_call_program public-keys $words[1] $needed --list-public-keys --list-options no-show-photos):%<*>}//(<|>)/} && return
> > + local public_keys=(${(@s.:.)${(f)"$(_call_program public-keys ${(q)words[1]} ${(q)needed} --list-public-keys --list-options no-show-photos --with-colons)"}})
> > + local -a uids_and_emails
> > + local i
> > + for i in {1..${#public_keys[@]}}; do
> > + if [[ ${public_keys[$i]} == "fpr" ]]; then
>
> This looks for the string "fpr" in any field, not just in the first column,
> doesn't it? (Already pointed out earlier)
Correct, when the search for "fpr" is done in this for loop, I can't
tell what element in the array was at the start of a line and which
wasn't.
>
> > + i=$((i + 1))
> > + local j=$i
> > + while [[ ${public_keys[$j]} != "fpr" ]] && [ $j -lt ${#public_keys[@]} ]; do
> > + if [[ ${public_keys[$j]} =~ "@" ]]; then
> > + local email="${public_keys[$j]}"
> > + local uid="${public_keys[$i]}"
> > + uids_and_emails+=("${uid}":"${email}")
>
> Here, colons and backslashes in $uid should be escaped for _describe. It may be
> easier to use the _describe syntax that takes two array names rather than one.
>
Doing so actually brings a whole lot better way of handling the
completion (IMO) and I really like it. Try this yourself:
local public_keys=(${(@s.:.)${(f)"$(_call_program public-keys ${(q)words[1]} ${(q)needed} --list-public-keys --list-options no-show-photos --with-colons)"}})
local -a uids emails
local i
for i in {1..${#public_keys[@]}}; do
if [[ ${public_keys[$i]} == "fpr" ]]; then
i=$((i + 1))
local j=$i
while [[ ${public_keys[$j]} != "fpr" ]] && [ $j -lt ${#public_keys[@]} ]; do
if [[ ${public_keys[$j]} =~ "@" ]]; then
emails+="${public_keys[$j]}"
uids+="${public_keys[$i]}"
i=$j
break
fi
j=$((j + 1))
done
i=$j
fi
done
_describe -t public-keys 'public key' emails uids
Is that what you meant by using two arrays?
> > + i=$j
> > + break
> > + fi
> > + j=$((j + 1))
>
> This assignment to $j seems to be a no-op, isn't it? The written value
> wouldn't be used by anything.
>
You are right, I removed `i=$j`.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author