[pacman-dev] [PATCH] this patch is to add zsh completion to pacman-key

Daniel.wallace at gatech.edu Daniel.wallace at gatech.edu
Sun Mar 25 23:54:24 EDT 2012


From: Daniel Wallace <daniel.wallace12 at gmail.com>

Sorry about my first email, hopefully this one will be in a better
format and without the entire first paragraph in the subject line.

The first thing I did was instead of running _pacman "$@" it now runs
_pacman_comp "$@". This function uses a switch statement on $service
so if pacman is the command it runs _pacman "$@" like it does right now,
but if the command is pacman-key, _pacman_key "$@" is run instead. This
function auto completes all the pacman-key flags and also provides the
description next to the arguments.  It also allows for completion of
dirs for arguments like --gpgdir, and autocompletes .sig files for
--verify, and gpg files for --import.

This patch will also allow for keyids and emails to be auto completed
from pacman-key --list-keys and other commands which use keyids.
the _keys() function is the one that does this, it #uses the first \<
to the end and remove first \> to the end to get all the
emails #the using the first \/ to end then remove first '\ ' to
the end this gets all the keyids (pub and sub) the ##uid*
removes all the .jpeg pictures with ids, and ##pubbring.gpg
removes the beginning line that lists where stuff is stored, ##\-\-*
removes the line of dashes at the beginning, but doesn't remove
email addresses with dashes in them.

Signed-off-by: Daniel Wallace <daniel.wallace12 at gmail.com>
---
 contrib/zsh_completion.in |   56 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 53 insertions(+), 3 deletions(-)

diff --git a/contrib/zsh_completion.in b/contrib/zsh_completion.in
index b30e960..608fa0c 100644
--- a/contrib/zsh_completion.in
+++ b/contrib/zsh_completion.in
@@ -1,4 +1,4 @@
-#compdef pacman pacman.static=pacman
+#compdef pacman pacman.static=pacman pacman-key
 
 # copy this file to /usr/share/zsh/site-functions/_pacman
 
@@ -332,5 +332,55 @@ _pacman() {
 	esac
 }
 
-# run the main dispatcher
-_pacman "$@"
+_pacman_key() {
+  _arguments \
+    '(- :)'{-h,--help}"[show help]" \
+    '(-a --add)*'{-a,--add}"[Add the specified keys (empty for stdin)]: :_files" \
+    '(-d --delete)*'{-d,--delete}"[Remove the Specified keyids]: :_keys" \
+    '(-e --export)*'{-e,--export}"[Export the specified or all keyids]: :_keys" \
+    '(-f --finger)*'{-f,--finger}"[List fingreprint for specidied or all keyids]: :_keys" \
+    '(-l --list-keys)*'{-l,--list-keys}"[List the specified or all keys]: :_keys" \
+    '(-r --recv-keys)*'{-r,--recv-keys}"[Fetch the specified keyids]: :_keys" \
+    '(-u --updatedb)*'{-u,--updatedb}"[Update the trustdb of pacman]" \
+    '(-v --verify)*'{-v,--verify}"[Verify the file specified by the signature]: :_files -g '*.sig'" \
+    '(-V --version)*'{-V,--version}"[Show program version]" \
+    '(--config)*'{*,--config}"[Use an alternate config file]: :_files" \
+    '(--edit-key)*'{*,--edit-key}"[Present a menu for key management task on keyids]: :_keys" \
+    '(--gpgdir)*'{*,--gpgdir}"[Set an alternate directory for GnuPG (instead of '/etc/pacman.d/gnupg')]: :_files -/" \
+    '(--import)*'{*,--import}"[Imports pubring.gpg from dir(s)]: :_files -g '*.gpg'" \
+    '(--import-trustdb)*'{*,--import-tb}"[Imports ownertrust values from trustdb.gpg in dir(s)]: :_files -g '*.gpg'" \
+    '(--init)*'{*,--init}"[Ensure the keyring is properly initialized]" \
+    '(--keyserver)*'{*,--keyserver}"[Specify a keyserver to use if necessary]" \
+    '(--list-sigs)*'{*,--list-sigs}"[List keys and their signatures]: :_keys" \
+    '(--lsign-key)*'{*,--lsign-key}"[Locally sign the specified keyid]: :_keys" \
+    '(--populate)*'{*,--populate}"[Reload the default keys from the (given) keyrings in '/usr/share/pacman/keyrings']: :_path_files -W /usr/share/pacman/keyrings" \
+    '(--refresh-keys)*'{*,--refresh-keys}"[Update specified or all keys from a keyserver]: :_keys"
+}
+
+_keys() {
+  local keys
+  #uses the first \< to the end and remove first \> to the end to get all the emails 
+  #the using the first \/ to end then remove first '\ ' to the end this gets all the keyids (pub and sub)
+  #the ##uid* removes all the .jpeg pictures with ids, and ##pubbring.gpg removes the beginning line that lists
+  #where stuff is stored, ##\-\-* removes the line of dashes at the beginning, but doesn't remove email addresses
+  #with dashes in them
+  keys=( ${${${${${${${${${(f)"$(pacman-key --list-keys 2>/dev/null)"}}##*\<}%%\>}##*\/}%%\ *}##uid*}##pubring.gpg}##\-\-*} )
+  _describe -t modules 'keys in keyring' keys && return 0
+}
+
+_pacman_comp() {
+  case "$service" in
+    pacman) 
+      _pacman "$@";;
+    pacman-key) 
+      _pacman_key "$@";;
+    *) 
+      _message "Error";;
+  esac
+}
+
+_pacman_comp "$@"
+
+
+
+# vim: ft=zsh sw=2 ts=2 et
-- 
1.7.9.4



More information about the pacman-dev mailing list