Merge pull request #1102 from Jguer/fix-completions

Update completions for zsh and bash to pacman 5.2
This commit is contained in:
J Guerreiro 2019-11-11 20:16:21 +00:00 committed by GitHub
commit 45da573821
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 48 deletions

View file

@ -3,10 +3,11 @@
_arch_compgen() {
local i r
COMPREPLY=($(compgen -W '$*' -- "$cur"))
for ((i=1; i < ${#COMP_WORDS[@]}-1; i++)); do
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
if [[ ${COMP_WORDS[i]} == ${COMPREPLY[r]} ]]; then
unset 'COMPREPLY[r]'
break
fi
done
done
@ -24,7 +25,8 @@ _arch_ptr2comp() {
}
_arch_incomp() {
local r="\s-(-${1#* }\s|\w*${1% *})"; [[ $COMP_LINE =~ $r ]]
local r="[[:space:]]-(-${1#* }[[:space:]]|[[:alnum:]_]*${1% *})"
[[ $COMP_LINE =~ $r ]]
}
_pacman_pkg() {
@ -38,7 +40,7 @@ _pacman_pkg() {
}
_yay_pkg() {
[ -z "$cur" ] && return
[ -z "$cur" ] && _pacman_pkg Slq && return
_arch_compgen "$(yay -Pc)"
}
@ -47,33 +49,35 @@ _pacman_repo_list() {
}
_yay() {
compopt -o default
local common core cur database files prev query remove sync upgrade o
local yays show getpkgbuild
COMPREPLY=()
_get_comp_words_by_ref cur prev
local cur prev words cword
_init_completion || return
database=('asdeps asexplicit')
files=('list machinereadable owns search refresh regex' 'l o s x y')
files=('list machinereadable refresh regex' 'l x y')
query=('changelog check deps explicit file foreign groups info list native owns
search unrequired upgrades' 'c e g i k l m n o p s t u')
remove=('cascade dbonly nodeps assume-installed nosave print recursive unneeded' 'c n p s u')
sync=('asdeps asexplicit clean dbonly downloadonly force groups ignore ignoregroup
sync=('asdeps asexplicit clean dbonly downloadonly overwrite groups ignore ignoregroup
info list needed nodeps assume-installed print refresh recursive search sysupgrade'
'c g i l p s u w y')
upgrade=('asdeps asexplicit force needed nodeps assume-installed print recursive' 'p')
common=('arch cachedir color config confirm dbpath debug gpgdir help hookdir logfile
noconfirm noprogressbar noscriptlet quiet root verbose')
#yay stuff
common+=('makepkg pacman tar git gpg gpgflags config requestsplitn sudoloop nosudoloop
redownload noredownload redownloadall rebuild rebuildall rebuildtree norebuild
sortby answerclean answerdiff answeredit answerupgrade noanswerclean noanswerdiff
noansweredit noanswerupgrade cleanmenu diffmenu editmenu upgrademenu cleanafter nocleanafter
nocleanmenu nodiffmenu noupgrademenu provides noprovides pgpfetch nopgpfetch
useask nouseask combinedupgrade nocombinedupgrade aur repo makepkgconf
nomakepkgconf askremovemake removemake noremovemake completioninterval aururl'
'b d h q r v')
'c g i l p s u w y')
upgrade=('asdeps asexplicit overwrite needed nodeps assume-installed print recursive' 'p')
core=('database files help query remove sync upgrade version' 'D F Q R S U V h')
##yay stuff
common=('arch cachedir color config confirm dbpath debug gpgdir help hookdir logfile
noconfirm noprogressbar noscriptlet quiet root verbose
makepkg pacman git gpg gpgflags config requestsplitn sudoloop nosudoloop
redownload noredownload redownloadall rebuild rebuildall rebuildtree norebuild
sortby answerclean answerdiff answeredit answerupgrade noanswerclean noanswerdiff
noansweredit noanswerupgrade cleanmenu diffmenu editmenu upgrademenu cleanafter nocleanafter
nocleanmenu nodiffmenu noupgrademenu provides noprovides pgpfetch nopgpfetch
useask nouseask combinedupgrade nocombinedupgrade aur repo makepkgconf
nomakepkgconf askremovemake removemake noremovemake completioninterval aururl
searchby batchinstall nobatchinstall'
'b d h q r v')
yays=('clean gendb' 'c')
show=('complete defaultconfig currentconfig stats news' 'c d g s w')
getpkgbuild=('force' 'f')
@ -84,38 +88,47 @@ _yay() {
if [[ $? != 0 ]]; then
_arch_ptr2comp core
elif [[ ! $prev =~ ^-\w*[Vbhr] &&
! $prev = --@(cachedir|color|config|dbpath|help|hookdir|gpgdir|logfile|root|version) ]]
then
[[ $cur = -* ]] && _arch_ptr2comp ${o#* } common ||
elif [[ ! $prev =~ ^-[[:alnum:]_]*[Vbhr] && ! $prev == --@(cachedir|color|config|dbpath|help|hookdir|gpgdir|logfile|root|version) ]]; then
[[ $cur == -* ]] && _arch_ptr2comp ${o#* } common ||
case ${o% *} in
D|R)
_pacman_pkg Qq;;
D | R)
_pacman_pkg Qq
;;
F)
_arch_incomp 'l list' && _pacman_pkg Slq;
;;
{ _arch_incomp 'l list' && _pacman_pkg Slq; } ||
_arch_incomp 'o owns' ||
compopt +o default
;;
Q)
{ _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;;
{ _arch_incomp 'g groups' && _pacman_pkg Qg sort; } ||
{ _arch_incomp 'p file' && _pacman_file; } ||
{ _arch_incomp 's search' && compopt +o default; } ||
{ _arch_incomp 'u upgrades' && compopt +o default; } ||
_arch_incomp 'o owns' ||
_pacman_pkg Qq
;;
S)
{ _arch_incomp 'g groups' && _pacman_pkg Sg; } ||
{ _arch_incomp 'l list' && _pacman_repo_list; } ||
_yay_pkg;;
G)
_yay_pkg;;
{ _arch_incomp 'g groups' && _pacman_pkg Sg; } ||
{ _arch_incomp 'l list' && _pacman_repo_list; } ||
{ _arch_incomp 's search' && compopt +o default; } ||
_yay_pkg
;;
U)
_pacman_file;;
_pacman_file
;;
G)
_yay_pkg
;;
esac
fi
true
}
_pacman_file() {
compopt -o filenames; _filedir 'pkg.tar*'
compopt -o filenames
_filedir 'pkg.tar*'
}
complete -F _yay -o default yay
complete -F _yay yay
# ex:et ts=2 sw=2 ft=sh

View file

@ -53,7 +53,6 @@ _pacman_opts_common=(
'--editorflags[Flags to pass to editor]'
'--makepkg[makepkg command to use]:makepkg:_files'
'--pacman[pacman command to use]:pacman:_files'
'--tar[bsdtar command to use]:tar:_files'
'--git[git command to use]:git:_files'
'--gpg[gpg command to use]:gpg:_files'
@ -103,6 +102,10 @@ _pacman_opts_common=(
'--gpgflags[Pass arguments to gpg]:gpgflags'
'--sudoloop[Loop sudo calls in the background to avoid timeout]'
'--nosudoloop[Do not loop sudo calls in the background]'
'--searchby[Search for packages using a specified field]'
'--sortby[Sort AUR results by a specific field during search]'
'--batchinstall[Build multiple AUR packages then install them together]'
'--nobatchinstall[Build and install each AUR package one by one]'
)
# options for passing to _arguments: options for --upgrade commands
@ -111,7 +114,7 @@ _pacman_opts_pkgfile=(
'*--nodeps[Skip dependency checks]'
'*--assume-installed[Add virtual package to satisfy dependencies]'
'--dbonly[Only remove database entry, do not remove files]'
'--force[Overwrite conflicting files]'
'--overwrite[Overwrite conflicting files]:file:_files -g "*"'
'--needed[Do not reinstall up to date packages]'
'--asdeps[mark packages as non-explicitly installed]'
'--asexplicit[mark packages as explicitly installed]'
@ -154,7 +157,7 @@ _pacman_opts_yay_modifiers=(
# -G
_pacman_opts_getpkgbuild_modifiers=(
{-f,--force}'[Force download for existing tar packages]'
{-f,--force}'[Force download for existing ABS packages]'
)
# -P
@ -189,8 +192,6 @@ _pacman_opts_database=(
_pacman_opts_files=(
{-l,--list}'[List the files owned by the queried package]:package:_pacman_completions_all_packages'
{-o,--owns}'[Query the package that owns]:files:_files'
{-s,--search}'[Search package file names for matching strings]:files:_files'
{-x,--regex}'[Enable searching using regular expressions]:regex:'
{-y,--refresh}'[Download fresh files databases from the server]'
'--machinereadable[Produce machine-readable output]'
@ -223,7 +224,7 @@ _pacman_opts_sync_modifiers=(
'*--ignoregroup[Ignore a group upgrade]:package group:_pacman_completions_all_groups'
'--asdeps[Install packages as non-explicitly installed]'
'--asexplicit[Install packages as explicitly installed]'
'--force[Overwrite conflicting files]'
'--overwrite[Overwrite conflicting files]:files:_files'
'--print-format[Specify how the targets should be printed]'
)