zsh-workers
 help / color / mirror / code / Atom feed
From: doron.behar@gmail.com
To: zsh-workers@zsh.org
Subject: [PATCH] _gpg: Use explicit UIDs for state = public keys.
Date: Thu,  7 Jun 2018 17:48:57 +0300	[thread overview]
Message-ID: <20180607144857.8835-1-doron.behar@gmail.com> (raw)

From: Doron Behar <doron.behar@gmail.com>

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
+        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.:.)${(f)"$(_call_program secret-keys ${(q)words[1]} ${(q)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
+        ${${(s.,.)${(M)${(f)${"$(_call_program ciphers ${(q)words[1]} ${(q)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.:.)${(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
+        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


             reply	other threads:[~2018-06-07 14:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-07 14:48 doron.behar [this message]
2018-06-09 18:21 ` Daniel Shahaf
2018-06-09 18:59   ` Doron Behar
2018-06-09 19:23     ` Daniel Shahaf
2018-06-09 19:41       ` Doron Behar
2018-06-18 19:47 doron.behar
2018-06-23 17:26 ` Doron Behar
2018-06-28 13:43   ` Doron Behar
2018-07-01 16:44     ` 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=20180607144857.8835-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).