[pacman-dev] [PATCH 1/2] patch to add zsh completion to pacman-key
this patch adds a _pacman_key function to the _pacman zsh site function so that zsh users can have completion for pacman-key <keyids> and other files which may be used with pacman-key Signed-off-by: Daniel Wallace <daniel.wallace@gatech.edu> --- contrib/zsh_completion.in | 58 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/contrib/zsh_completion.in b/contrib/zsh_completion.in index b30e960..73ce42f 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 @@ -286,7 +286,7 @@ _pacman_get_command() { } # main dispatcher -_pacman() { +_pacman_zsh_comp() { case $words[2] in -Q*g*) # ipkg groups _arguments -s : \ @@ -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-key) + _pacman_key "$@";; + pacman) + _pacman_zsh_comp "$@";; + *) + _message "Error";; + esac +} + +_pacman_comp "$@" + + + +# vim: ft=zsh sw=2 ts=2 et -- 1.7.10
right now the only completion for zsh for makepkg comes from pkgtool, and the 2 options that come from that are --chown and --linkadd which aren't options for makepkg anyway. This should add completion for all the flags for makepkg Signed-off-by: Daniel Wallace <daniel.wallace@gatech.edu> --- contrib/zsh_completion.in | 175 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 166 insertions(+), 9 deletions(-) diff --git a/contrib/zsh_completion.in b/contrib/zsh_completion.in index 73ce42f..4bafafa 100644 --- a/contrib/zsh_completion.in +++ b/contrib/zsh_completion.in @@ -1,4 +1,4 @@ -#compdef pacman pacman.static=pacman pacman-key +#compdef pacman pacman.static=pacman pacman-key makepkg # copy this file to /usr/share/zsh/site-functions/_pacman @@ -239,7 +239,7 @@ _pacman_completions_all_packages() { typeset -U packages _wanted packages expl "packages" compadd - "${(@)packages}" - repositories=(${(o)${${${(M)${(f)"$(<@sysconfdir@/pacman.conf)"}:#\[*}/\[/}/\]/}:#options}) + repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options}) typeset -U repositories _wanted repo_packages expl "repository/package" compadd -S "/" $repositories fi @@ -257,15 +257,15 @@ _pacman_completions_installed_groups() { # provides completions for installed packages _pacman_completions_installed_packages() { local -a cmd packages packages_long - packages_long=(@localstatedir@/lib/pacman/local/*(/)) - packages=( ${${packages_long#@localstatedir@/lib/pacman/local/}%-*-*} ) + packages_long=(/var/lib/pacman/local/*(/)) + packages=( ${${packages_long#/var/lib/pacman/local/}%-*-*} ) compadd "$@" -a packages } # provides completions for repository names _pacman_completions_repositories() { local -a cmd repositories - repositories=(${(o)${${${(M)${(f)"$(<@sysconfdir@/pacman.conf)"}:#\[*}/\[/}/\]/}:#options}) + repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options}) # Uniq the array typeset -U repositories compadd "$@" -a repositories @@ -333,7 +333,7 @@ _pacman_zsh_comp() { } _pacman_key() { - _arguments \ + _arguments -s \ '(- :)'{-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" \ @@ -368,8 +368,167 @@ _keys() { _describe -t modules 'keys in keyring' keys && return 0 } + +# vim: ft=zsh sw=2 ts=2 et +#compdef makepkg +_makepkg_opts_common=( + '-s[Install missing dependencies with pacman]' + '-i[Install package after successful build]' + '-A[Ignore incomplete arch field in PKGBUILD]' + '-c[Clean up work files after build]' + '-d[Skip all dependency checks]' + '-e[Do not extract source files (use existing src/ dir)]' + '-f[Overwrite existing package]' + '-g[Generate integrity checks for source files]' + '-h[Show help message and exit]' + '-L[Log package build process]' + '-m[Disable colorized output messages]' + '-o[Download and extract files only]' + '-p[Use an alternate build script (instead of 'PKGBUILD')]: :_files' + '-r[Remove installed dependencies after a successful build]' + '-R[Repackage contents of the package without rebuilding]' + '-S[Generate a source-only tarball without downloading sources]' + ) + +_makepkg_action_none(){ + _arguments \ + "$_makepkg_opts_common[@]"\ + "$_double_makepkg[@]" +} +_double_makepkg=( + '--ignorearch[Ignore incomplete arch field in PKGBUILD]' + '--clean[Clean up work files after build]' + '--nodeps[Skip all dependency checks]' + '--noextract[Do not extract source files (use existing src/ dir)]' + '--force[Overwrite existing package]' + '--geninteg[Generate integrity checks for source files]' + '--help[Show help message and exit]' + '--install[Install package after successful build]' + '--log[Log package build process]' + '--nocolor[Disable colorized output messages]' + '--nobuild[Download and extract files only]' + '--rmdeps[Remove installed dependencies after a successful build]' + '--repackage[Repackage contents of the package without rebuilding]' + '--syncdeps[Install missing dependencies with pacman]' + '--source[Generate a source-only tarball without downloading sources]' + '--allsource[Generate a source-only tarball including downloaded source]' + '--asroot[Allow makepkg to run as root user]' + '--check[Run check() function in the PKGBUILD]' + '--config[Use an alternate config file instead of '/etc/makepkg.conf']: :_files' + '--holdver[Prevent automatic version bumping for development PKGBUILDs]' + '--key[Specify key to use for gpg signing instead of the default]: :_keys' + '--nocheck[Do not run the check() function in the PKGBUILD]' + '--nosign[Do not create a signature for the package]' + '--pkg[Only build listed packages from a split package]' + '--sign[Sign the resulting package with gpg]' + '--skipchecksums[Do not verify checksums of the source files]' + '--skipinteg[do not perform any verification checks on source files]' + '--skippgpcheck[Do not verify source files with PGP signatures]' + '--noconfirm[do not ask for confirmation when resolving dependencies]' + '--noprogressbar[Do not show a progress bar when downloading files]' + ) +_makepkg(){ + case $words[2] in + -A*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + -c*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + -d*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + -e*) + _arguments \ + "$_makepkg_opts_common[@]" + "$_double_makepkg[@]" + ;; + -f*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + -g*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + -h*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + -i*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + -L*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + -m*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + -o*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + -p*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + -r*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + -R*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + -S*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + -s*) + _arguments \ + "$_makepkg_opts_common[@]" \ + "$_double_makepkg[@]" + ;; + --* ) + _arguments -s \ + "$_double_makepkg[@]" + ;; + - )_makepkg_action_none ;; + * ) return 1;; + esac +# case "$words[3]" in +# --) +# _arguments -s \ +# "$_double_makepkg[@]" +# ;; +# - )_makepkg_action_none ;; +# *) return 1;; +# esac +} _pacman_comp() { case "$service" in + makepkg) + _makepkg "$@";; pacman-key) _pacman_key "$@";; pacman) @@ -379,8 +538,6 @@ _pacman_comp() { esac } -_pacman_comp "$@" +_pacman_comp - -# vim: ft=zsh sw=2 ts=2 et -- 1.7.10
On Sun, Apr 15, 2012 at 01:16:43PM -0400, Daniel Wallace wrote:
this patch adds a _pacman_key function to the _pacman zsh site function so that zsh users can have completion for pacman-key <keyids> and other files which may be used with pacman-key
Signed-off-by: Daniel Wallace <daniel.wallace@gatech.edu> ---
I don't know ZSH completion at all, but I gave this a test run and it seems to work. I only have one comment, which I've left inline...
contrib/zsh_completion.in | 58 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-)
diff --git a/contrib/zsh_completion.in b/contrib/zsh_completion.in index b30e960..73ce42f 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
@@ -286,7 +286,7 @@ _pacman_get_command() { }
# main dispatcher -_pacman() { +_pacman_zsh_comp() { case $words[2] in -Q*g*) # ipkg groups _arguments -s : \ @@ -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}##\-\-*} )
I realize that the goal here is to avoid forking, but this is unreadable. Using awk, I can cook up the below which should accomplish the same and seems infinitely more maintainable. pacman-key --list-keys 2>/dev/null | awk ' $1 == "pub" { # key id split($2, a, "/"); print a[2] } $1 == "uid" { # email l = len($NF) print substr($NF, 2, l - 2) } '
+ _describe -t modules 'keys in keyring' keys && return 0 +} + +_pacman_comp() { + case "$service" in + pacman-key) + _pacman_key "$@";; + pacman) + _pacman_zsh_comp "$@";; + *) + _message "Error";; + esac +} + +_pacman_comp "$@" + + + +# vim: ft=zsh sw=2 ts=2 et -- 1.7.10
On Sun, Apr 15, 2012 at 09:02:05PM -0400, Dave Reisner wrote:
On Sun, Apr 15, 2012 at 01:16:43PM -0400, Daniel Wallace wrote:
this patch adds a _pacman_key function to the _pacman zsh site function so that zsh users can have completion for pacman-key <keyids> and other files which may be used with pacman-key
Signed-off-by: Daniel Wallace <daniel.wallace@gatech.edu> ---
I don't know ZSH completion at all, but I gave this a test run and it seems to work. I only have one comment, which I've left inline...
Yay, replying to myself... if we're going to be merging my parseopts branch, this greatly changes option parsing semantics for pacman-key. I only tested this against 4.0.3, but I suspect it does a lot of things wrong against that branch...
contrib/zsh_completion.in | 58 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-)
diff --git a/contrib/zsh_completion.in b/contrib/zsh_completion.in index b30e960..73ce42f 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
@@ -286,7 +286,7 @@ _pacman_get_command() { }
# main dispatcher -_pacman() { +_pacman_zsh_comp() { case $words[2] in -Q*g*) # ipkg groups _arguments -s : \ @@ -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}##\-\-*} )
I realize that the goal here is to avoid forking, but this is unreadable. Using awk, I can cook up the below which should accomplish the same and seems infinitely more maintainable.
pacman-key --list-keys 2>/dev/null | awk ' $1 == "pub" { # key id split($2, a, "/"); print a[2] } $1 == "uid" { # email l = len($NF) print substr($NF, 2, l - 2) } '
+ _describe -t modules 'keys in keyring' keys && return 0 +} + +_pacman_comp() { + case "$service" in + pacman-key) + _pacman_key "$@";; + pacman) + _pacman_zsh_comp "$@";; + *) + _message "Error";; + esac +} + +_pacman_comp "$@" + + + +# vim: ft=zsh sw=2 ts=2 et -- 1.7.10
I was told to only use zsh for zsh completion, However if it is ok to use awk instead, I can use that. Also about parse opts I can remove the : :_files or : :_keys for anything that does not allow for arguments in the parseopts branch, whenever it is merged. On Sun, Apr 15, 2012 at 09:02:05PM -0400, Dave Reisner wrote:
On Sun, Apr 15, 2012 at 01:16:43PM -0400, Daniel Wallace wrote:
this patch adds a _pacman_key function to the _pacman zsh site function so that zsh users can have completion for pacman-key <keyids> and other files which may be used with pacman-key
Signed-off-by: Daniel Wallace <daniel.wallace@gatech.edu> ---
I don't know ZSH completion at all, but I gave this a test run and it seems to work. I only have one comment, which I've left inline...
contrib/zsh_completion.in | 58 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-)
diff --git a/contrib/zsh_completion.in b/contrib/zsh_completion.in index b30e960..73ce42f 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
@@ -286,7 +286,7 @@ _pacman_get_command() { }
# main dispatcher -_pacman() { +_pacman_zsh_comp() { case $words[2] in -Q*g*) # ipkg groups _arguments -s : \ @@ -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}##\-\-*} )
I realize that the goal here is to avoid forking, but this is unreadable. Using awk, I can cook up the below which should accomplish the same and seems infinitely more maintainable.
pacman-key --list-keys 2>/dev/null | awk ' $1 == "pub" { # key id split($2, a, "/"); print a[2] } $1 == "uid" { # email l = len($NF) print substr($NF, 2, l - 2) } '
+ _describe -t modules 'keys in keyring' keys && return 0 +} + +_pacman_comp() { + case "$service" in + pacman-key) + _pacman_key "$@";; + pacman) + _pacman_zsh_comp "$@";; + *) + _message "Error";; + esac +} + +_pacman_comp "$@" + + + +# vim: ft=zsh sw=2 ts=2 et -- 1.7.10
participants (2)
-
Daniel Wallace
-
Dave Reisner