summaryrefslogtreecommitdiff
path: root/contrib/bash_completion.in
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bash_completion.in')
-rw-r--r--contrib/bash_completion.in66
1 files changed, 43 insertions, 23 deletions
diff --git a/contrib/bash_completion.in b/contrib/bash_completion.in
index 8983c92b..b0901af2 100644
--- a/contrib/bash_completion.in
+++ b/contrib/bash_completion.in
@@ -27,17 +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
- if [[ $cur = -* &&
- $prev != -@(a|-add|c|-config|g|-gpgdir|h|-help|import?(-trustdb)) ]]; then
- 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')
+ 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')
+
+ # 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
}
@@ -47,9 +74,9 @@ _makepkg() {
COMPREPLY=()
_get_comp_words_by_ref cur prev
if [[ $cur = -* && ! $prev =~ ^-(-(config|help)$|\w*[Chp]) ]]; then
- opts=('allsource asroot check clean config force geninteg help holdver ignorearch
- install log nobuild nocheck nocolor noconfirm nodeps noextract noprogressbar
- nosign pkg repackage rmdeps sign skipinteg source syncdeps'
+ opts=('allsource asdeps asroot check clean config force geninteg help holdver ignorearch
+ install log nobuild nocheck nocolor noconfirm nodeps noextract
+ noprogressbar nosign pkg repackage rmdeps sign skipinteg source syncdeps'
'A L R S c d e f g h i m o p r s')
_arch_ptr2comp opts
fi
@@ -76,8 +103,8 @@ _pacman() {
remove=('cascade dbonly nodeps nosave print recursive unneeded' 'c n p s u')
sync=('asdeps asexplicit clean dbonly downloadonly force groups ignore ignoregroup
info list needed nodeps print refresh recursive search sysupgrade'
- 'c f g i l p s u w y')
- upgrade=('asdeps asexplicit force needed nodeps print recursive' 'f p')
+ 'c g i l p s u w y')
+ upgrade=('asdeps asexplicit force needed nodeps print recursive' 'p')
common=('arch cachedir config dbpath debug help logfile noconfirm
noprogressbar noscriptlet quiet root verbose' 'b d h q r v')
core=('database help query remove sync upgrade version' 'D Q R S U V h')
@@ -111,18 +138,11 @@ _pacman() {
true
}
-if [[ $(type -t compopt) = "builtin" ]]; then
- _pacman_file() {
- compopt -o filenames; _filedir 'pkg.tar*'
- }
- complete -F _pacman -o default pacman
-else
- _pacman_file() {
- _filedir 'pkg.tar*'
- }
- complete -F _pacman -o filenames -o default pacman
-fi
+_pacman_file() {
+ compopt -o filenames; _filedir 'pkg.tar*'
+}
+complete -F _pacman -o default pacman
complete -F _makepkg -o default makepkg
complete -F _pacman_key -o default pacman-key