2010-05-18 18:26:47 -04:00
|
|
|
# This file is in the public domain.
|
|
|
|
|
|
|
|
_arch_compgen() {
|
|
|
|
local i r
|
|
|
|
COMPREPLY=($(compgen -W '$*' -- "$cur"))
|
|
|
|
for ((i=1; i < ${#COMP_WORDS[@]}-1; i++)); do
|
|
|
|
for r in ${!COMPREPLY[@]}; do
|
|
|
|
if [[ ${COMP_WORDS[i]} = ${COMPREPLY[r]} ]]; then
|
|
|
|
unset 'COMPREPLY[r]'; break
|
|
|
|
fi
|
2007-02-16 14:37:00 -05:00
|
|
|
done
|
2010-05-18 18:26:47 -04:00
|
|
|
done
|
2007-02-16 14:37:00 -05:00
|
|
|
}
|
|
|
|
|
2010-05-18 18:26:47 -04:00
|
|
|
_arch_ptr2comp() {
|
|
|
|
local list= x y
|
|
|
|
for x; do
|
|
|
|
for y in '0 --' '1 -'; do
|
|
|
|
eval 'set -- ${'$x'[${y% *}]}'
|
|
|
|
list+=\ ${@/#/${y#* }}
|
|
|
|
done
|
|
|
|
done
|
|
|
|
_arch_compgen $list
|
2007-02-16 14:37:00 -05:00
|
|
|
}
|
|
|
|
|
2010-05-18 18:26:47 -04:00
|
|
|
_arch_incomp() {
|
|
|
|
local r="\s-(-${1#* }\s|\w*${1% *})"; [[ $COMP_LINE =~ $r ]]
|
2007-02-16 14:37:00 -05:00
|
|
|
}
|
|
|
|
|
2012-04-15 22:13:49 -04:00
|
|
|
_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)
|
|
|
|
}'
|
|
|
|
}
|
|
|
|
|
2011-09-25 14:32:15 -04:00
|
|
|
_pacman_key() {
|
2012-04-15 22:13:49 -04:00
|
|
|
local o cur opts prev wantfiles
|
2011-09-25 14:32:15 -04:00
|
|
|
COMPREPLY=()
|
|
|
|
_get_comp_words_by_ref cur prev
|
2013-03-20 03:27:50 -04:00
|
|
|
opts=('add config delete edit-key export finger gpgdir
|
|
|
|
help import import-trustdb init keyserver list-keys list-sigs
|
|
|
|
lsign-key nocolor populate recv-keys refresh-keys updatedb
|
|
|
|
verify version'
|
2012-03-27 20:29:48 -04:00
|
|
|
'a d e f h l r u v V')
|
2012-04-15 22:13:49 -04:00
|
|
|
|
|
|
|
# operations for which we want to complete keyids
|
|
|
|
for o in 'd delete' 'e export' 'f finger' 'l list-keys' 'r recv-keys' \
|
2013-03-20 03:27:50 -04:00
|
|
|
'edit-key' 'list-sigs' 'lsign-key' 'refresh-keys'; do
|
2012-04-15 22:13:49 -04:00
|
|
|
_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
|
2011-09-25 14:32:15 -04:00
|
|
|
_arch_ptr2comp opts
|
2012-04-15 22:13:49 -04:00
|
|
|
elif [[ $prev = @(-k|--keyserver) ]]; then
|
|
|
|
return
|
|
|
|
elif [[ $prev != $wantfiles && $o ]]; then
|
|
|
|
COMPREPLY=($(compgen -W '$(_pacman_keyids)' -- "$cur"))
|
2011-09-25 14:32:15 -04:00
|
|
|
fi
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2010-05-18 18:26:47 -04:00
|
|
|
_makepkg() {
|
|
|
|
local cur opts prev
|
2007-02-16 14:37:00 -05:00
|
|
|
COMPREPLY=()
|
2010-10-13 00:46:35 -04:00
|
|
|
_get_comp_words_by_ref cur prev
|
2016-01-26 05:29:49 -05:00
|
|
|
if [[ $cur = -* && ! $prev =~ ^-(-(config|help|key|version)$|\w*[Vhp]) ]]; then
|
|
|
|
opts=('allsource asdeps check clean cleanbuild config force geninteg help
|
|
|
|
holdver ignorearch install key log needed noarchive nobuild nocheck
|
|
|
|
nocolor noconfirm nodeps noextract noprepare noprogressbar nosign
|
|
|
|
packagelist printsrcinfo repackage rmdeps sign skipchecksums
|
|
|
|
skipinteg skippgpcheck source syncdeps verifysource version'
|
|
|
|
'A C L R S c d e f g h i m o p r s')
|
2010-05-18 18:26:47 -04:00
|
|
|
_arch_ptr2comp opts
|
2007-02-16 14:37:00 -05:00
|
|
|
fi
|
2010-05-18 18:26:47 -04:00
|
|
|
true
|
2007-02-16 14:37:00 -05:00
|
|
|
}
|
|
|
|
|
2010-05-18 18:26:47 -04:00
|
|
|
_pacman_pkg() {
|
|
|
|
_arch_compgen "$(
|
|
|
|
if [[ $2 ]]; then
|
2012-01-19 17:23:57 -05:00
|
|
|
\pacman -$1 2>/dev/null | \cut -d' ' -f1 | \sort -u
|
2010-05-18 18:26:47 -04:00
|
|
|
else
|
2012-01-19 17:23:57 -05:00
|
|
|
\pacman -$1 2>/dev/null
|
2007-02-18 23:13:13 -05:00
|
|
|
fi
|
2010-05-18 18:26:47 -04:00
|
|
|
)"
|
2007-02-16 14:37:00 -05:00
|
|
|
}
|
|
|
|
|
2010-05-18 18:26:47 -04:00
|
|
|
_pacman() {
|
|
|
|
local common core cur database prev query remove sync upgrade o
|
|
|
|
COMPREPLY=()
|
2010-10-13 00:46:35 -04:00
|
|
|
_get_comp_words_by_ref cur prev
|
2010-05-18 18:26:47 -04:00
|
|
|
database=('asdeps asexplicit')
|
2016-01-26 05:43:39 -05:00
|
|
|
files=('list machinereadable owns search refresh regex' 'l o s x y')
|
2010-05-18 18:26:47 -04:00
|
|
|
query=('changelog check deps explicit file foreign groups info list owns
|
|
|
|
search unrequired upgrades' 'c e g i k l m o p s t u')
|
2014-11-05 03:24:35 -05:00
|
|
|
remove=('cascade dbonly nodeps assume-installed nosave print recursive unneeded' 'c n p s u')
|
2011-08-19 16:48:09 -04:00
|
|
|
sync=('asdeps asexplicit clean dbonly downloadonly force groups ignore ignoregroup
|
2014-11-05 03:24:35 -05:00
|
|
|
info list needed nodeps assume-installed print refresh recursive search sysupgrade'
|
2011-10-11 13:35:33 -04:00
|
|
|
'c g i l p s u w y')
|
2014-11-05 03:24:35 -05:00
|
|
|
upgrade=('asdeps asexplicit force needed nodeps assume-installed print recursive' 'p')
|
2016-01-26 05:43:39 -05:00
|
|
|
common=('arch cachedir color config confirm dbpath debug gpgdir help hookdir logfile
|
|
|
|
noconfirm noprogressbar noscriptlet quiet root verbose' 'b d h q r v')
|
|
|
|
core=('database files help query remove sync upgrade version' 'D F Q R S U V h')
|
2010-05-18 18:26:47 -04:00
|
|
|
|
2016-01-26 05:43:39 -05:00
|
|
|
for o in 'D database' 'F files' 'Q query' 'R remove' 'S sync' 'U upgrade'; do
|
2010-05-18 18:26:47 -04:00
|
|
|
_arch_incomp "$o" && break
|
2007-02-16 14:37:00 -05:00
|
|
|
done
|
|
|
|
|
2010-05-18 18:26:47 -04:00
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
_arch_ptr2comp core
|
2010-07-26 10:49:43 -04:00
|
|
|
elif [[ ! $prev =~ ^-\w*[Vbhr] &&
|
2016-01-26 05:43:39 -05:00
|
|
|
! $prev = --@(cachedir|color|config|dbpath|help|hookdir|gpgdir|logfile|root|version) ]]
|
2010-05-18 18:26:47 -04:00
|
|
|
then
|
|
|
|
[[ $cur = -* ]] && _arch_ptr2comp ${o#* } common ||
|
|
|
|
case ${o% *} in
|
|
|
|
D|R)
|
|
|
|
_pacman_pkg Qq;;
|
2016-01-26 05:43:39 -05:00
|
|
|
F)
|
|
|
|
_arch_incomp 'l list' && _pacman_pkg Slq;
|
|
|
|
;;
|
2007-02-16 14:37:00 -05:00
|
|
|
Q)
|
2010-05-18 18:26:47 -04:00
|
|
|
{ _arch_incomp 'g groups' && _pacman_pkg Qg sort; } ||
|
|
|
|
{ _arch_incomp 'p file' && _pacman_file; } ||
|
|
|
|
_arch_incomp 'o owns' || _arch_incomp 'u upgrades' ||
|
|
|
|
_pacman_pkg Qq;;
|
2007-02-16 14:37:00 -05:00
|
|
|
S)
|
2010-05-18 18:26:47 -04:00
|
|
|
{ _arch_incomp 'g groups' && _pacman_pkg Sg; } ||
|
|
|
|
{ _arch_incomp 'l list' && _pacman_pkg Sl sort; } ||
|
|
|
|
_pacman_pkg Slq;;
|
|
|
|
U)
|
|
|
|
_pacman_file;;
|
|
|
|
esac
|
2007-02-16 14:37:00 -05:00
|
|
|
fi
|
2010-05-18 18:26:47 -04:00
|
|
|
true
|
2007-02-16 14:37:00 -05:00
|
|
|
}
|
2010-05-18 18:26:47 -04:00
|
|
|
|
2012-03-27 20:25:50 -04:00
|
|
|
_pacman_file() {
|
|
|
|
compopt -o filenames; _filedir 'pkg.tar*'
|
|
|
|
}
|
2010-06-21 22:30:44 -04:00
|
|
|
|
2012-03-27 20:25:50 -04:00
|
|
|
complete -F _pacman -o default pacman
|
2010-05-18 18:26:47 -04:00
|
|
|
complete -F _makepkg -o default makepkg
|
2011-09-25 14:32:15 -04:00
|
|
|
complete -F _pacman_key -o default pacman-key
|
2010-05-18 18:26:47 -04:00
|
|
|
|
|
|
|
# ex:et ts=2 sw=2 ft=sh
|