Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/contrib/bash_completion.in
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-04-15 22:13:49 -0400
committerDan McGee <dan@archlinux.org>2012-04-24 08:38:36 -0500
commite07a2ab45e67e8ee989f9d102051481a35329b09 (patch)
tree2f8a778cd056a03e3863334addc94d0e0f8273b1 /contrib/bash_completion.in
parent62dbf7ec43f4420c20b78ec647594c3f63558a39 (diff)
bash_completion: update for changes to pacman-key
- only do file completion for options which expect files - add completion for possible key ids when a relevant operation is in COMPWORDS. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Diffstat (limited to 'contrib/bash_completion.in')
-rw-r--r--contrib/bash_completion.in35
1 files changed, 30 insertions, 5 deletions
diff --git a/contrib/bash_completion.in b/contrib/bash_completion.in
index 95a27702..1b265e0c 100644
--- a/contrib/bash_completion.in
+++ b/contrib/bash_completion.in
@@ -27,19 +27,44 @@ _arch_incomp() {
local r="\s-(-${1#* }\s|\w*${1% *})"; [[ $COMP_LINE =~ $r ]]
}
+_pacman_keyids() {
+ \pacman-key --list-keys 2>/dev/null | awk '
+ $1 == "pub" {
+ # key id
+ split($2, a, "/"); print a[2]
+ }
+ $1 == "uid" {
+ # email
+ if (match($NF, /<[^>]+>/))
+ print substr($NF, RSTART + 1, RLENGTH - 2)
+ }'
+}
+
_pacman_key() {
- local cur opts prev
+ local o cur opts prev wantfiles
COMPREPLY=()
_get_comp_words_by_ref cur prev
opts=('add delete export finger help list-keys recv-keys updatedb verify
version config edit-key gpgdir import import-trustdb init keyserver
list-sigs lsign-key populate refresh-keys'
'a d e f h l r u v V')
- if [[ $prev = 'pacman-key' ]]; then
- _arch_ptr2comp opts
- elif [[ $cur = -* &&
- $prev != -@(a|-add|c|-config|g|-gpgdir|h|-help|import?(-trustdb)) ]]; then
+
+ # operations for which we want to complete keyids
+ for o in 'd delete' 'e export' 'f finger' 'l list-keys' 'r recv-keys' \
+ 'edit-key' 'list-sigs' 'refresh-keys'; do
+ _arch_incomp "$o" && break
+ unset o
+ done
+
+ # options for which we want file completion
+ wantfiles='-@(c|-config|g|-gpgdir)'
+
+ if [[ $prev = 'pacman-key' || ( $cur = -* && $prev != $wantfiles ) ]]; then
_arch_ptr2comp opts
+ elif [[ $prev = @(-k|--keyserver) ]]; then
+ return
+ elif [[ $prev != $wantfiles && $o ]]; then
+ COMPREPLY=($(compgen -W '$(_pacman_keyids)' -- "$cur"))
fi
true
}