From: doron.behar@gmail.com
To: zsh-workers@zsh.org
Subject: [PATCH] _gpg: Use explicit UIDs for public / secret keys.
Date: Sat, 2 Jun 2018 18:26:51 +0300 [thread overview]
Message-ID: <20180602152651.16904-1-doron.behar@gmail.com> (raw)
From: Doron Behar <doron.behar@gmail.com>
Use the `--with-colons` option and parse the output.
---
Completion/Unix/Command/_gpg | 69 ++++++++++++++++++++++++++++++++----
1 file changed, 63 insertions(+), 6 deletions(-)
diff --git a/Completion/Unix/Command/_gpg b/Completion/Unix/Command/_gpg
index 48a36eff2..7e707c5f6 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.:.)$(_call_program public-keys eval IFS=$'\n' $words[1] $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
+ 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}")
+ i=$j
+ break
+ fi
+ j=$((j + 1))
+ done
+ i=$j
+ fi
+ done
+ _describe -t public-keys 'public key' uids_and_emails
;;
secret-keys)
- _wanted secret-keys expl 'secret key' compadd \
- ${${(Mo)$(_call_program secret-keys $words[1] $needed --list-secret-keys --list-options no-show-photos):%<*>}//(<|>)/} && return
+ local secret_keys=(${(@s.:.)$(_call_program secret-keys eval IFS=$'\n' $words[1] $needed --list-secret-keys --list-options no-show-photos --with-colons)})
+ local -a uids_and_emails
+ local i
+ for i in {1..${#secret_keys[@]}}; do
+ if [[ ${secret_keys[$i]} == "fpr" ]]; then
+ i=$((i + 1))
+ local j=$i
+ while [[ ${secret_keys[$j]} != "fpr" ]] && [ $j -lt ${#secret_keys[@]} ]; do
+ if [[ ${secret_keys[$j]} =~ "@" ]]; then
+ local email="${secret_keys[$j]}"
+ local uid=${secret_keys[$i]}
+ uids_and_emails+=("${uid}":"${email}")
+ i=$j
+ break
+ fi
+ j=$((j + 1))
+ done
+ i=$j
+ fi
+ done
+ _describe -t secret-keys 'secret key' uids_and_emails
;;
ciphers)
_wanted ciphers expl cipher compadd \
${${(s.,.)${(M)${(f)${"$(_call_program ciphers $words[1] $needed --version)"}//,$'\n' #/, }:#Cipher*}#*:}# } && return
;;
(public-keyids)
- _wanted public-keys expl 'public keyid' \
- compadd ${(M)${${(f)"$(_call_program public-keyids $words[1] $needed --list-public-keys --list-options no-show-photos)"}## #}:#[0-9A-F](#c40)} && return
+ local public_keys=(${(@s.:.)$(_call_program public-keyids eval IFS=$'\n' $words[1] $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
+ 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}")
+ i=$j
+ break
+ fi
+ j=$((j + 1))
+ done
+ i=$j
+ fi
+ done
+ _describe -t public-keyids 'public keyids' uids_and_emails
;;
(option-list)
_sequence _wanted options expl option \
--
2.17.1
next reply other threads:[~2018-06-02 15:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-02 15:26 doron.behar [this message]
2018-06-03 21:43 ` Daniel Shahaf
2018-06-05 15:47 ` Doron Behar
2018-06-07 6:40 ` Daniel Shahaf
2018-06-07 15:50 ` Doron Behar
2018-06-09 20:09 doron.behar
2018-06-09 20:39 ` Daniel Shahaf
2018-06-12 10:54 ` Doron Behar
2018-06-12 19:22 ` Matthew Martin
2018-06-12 22:14 ` Phil Pennock
2018-06-13 15:17 ` Doron Behar
2018-06-14 10:06 ` Daniel Shahaf
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=20180602152651.16904-1-doron.behar@gmail.com \
--to=doron.behar@gmail.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).