Skip to content

Commit

Permalink
feat(aura): renew bash completions
Browse files Browse the repository at this point in the history
  • Loading branch information
fosskers committed Jul 25, 2024
1 parent e15ae0a commit 4805a1e
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions misc/completions/bashcompletion.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is in the public domain.

_aura_compgen() {
_arch_compgen() {
local i r
COMPREPLY=($(compgen -W '$*' -- "$cur"))
for ((i=1; i < ${#COMP_WORDS[@]}-1; i++)); do
Expand All @@ -12,42 +12,46 @@ _aura_compgen() {
done
}

_aura_ptr2comp() {
_arch_ptr2comp() {
local list= x y
for x; do
for y in '0 --' '1 -'; do
eval 'set -- ${'$x'[${y% *}]}'
list+=\ ${@/#/${y#* }}
done
done
_aura_compgen $list
_arch_compgen $list
}

_aura_incomp() {
_arch_incomp() {
local r="[[:space:]]-(-${1#* }[[:space:]]|[[:alnum:]_]*${1% *})"; [[ $COMP_LINE =~ $r ]]
}

_aura_pkg() {
_aura_compgen "$(
_arch_compgen "$(
if [[ $2 ]]; then
\pacman -$1 2>/dev/null | \cut -d' ' -f1 | \sort -u
\aura -$1 2>/dev/null | \cut -d' ' -f1 | \sort -u
else
\pacman -$1 2>/dev/null
\aura -$1 2>/dev/null
fi
)"
}

_aura_repo_list() {
_aura_compgen "$(pacman-conf --repo-list)"
_arch_compgen "$(pacman-conf --repo-list)"
}

_aura() {
compopt -o default
local common core database files query remove sync upgrade o
local common core aursync cache database files viewlog orphans query remove sync upgrade o
local cur prev words cword
_init_completion || return
aursync=('info open pkgbuild search sysupgrade provides clone' 'i o p s u v w')
cache=('backup clean info list missing search invalid refresh' 'b c i l m s t y')
database=('asdeps asexplicit')
files=('list machinereadable refresh regex' 'l x y')
viewlog=('info search' 'i s')
orphans=('adopt abandon elderly' 'a j e')
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')
Expand All @@ -57,36 +61,35 @@ _aura() {
upgrade=('asdeps asexplicit 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' 'b d h q r v')
core=('aursync save downgrade database files viewlog help orphans analysis query remove sync upgrade version' 'A B C D F L O P Q R S U V h')
core=('aursync cache database files viewlog orphans help query remove sync upgrade version' 'A C D F L O Q R S U V h')

for o in 'D database' 'F files' 'Q query' 'R remove' 'S sync' 'U upgrade'; do
_aura_incomp "$o" && break
for o in 'A aursync' 'C cache' 'D database' 'F files' 'L viewlog' 'O orphans' 'Q query' 'R remove' 'S sync' 'U upgrade'; do
_arch_incomp "$o" && break
done

if [[ $? != 0 ]]; then
_aura_ptr2comp core
_arch_ptr2comp core
elif [[ ! $prev =~ ^-[[:alnum:]_]*[Vbhr] &&
! $prev = --@(cachedir|color|config|dbpath|help|hookdir|gpgdir|logfile|root|version) ]]
then
[[ $cur = -* ]] && _aura_ptr2comp ${o#* } common ||
[[ $cur = -* ]] && _arch_ptr2comp ${o#* } common ||
case ${o% *} in
# Pacman Commands
D|R)
_aura_pkg Qq;;
F)
{ _aura_incomp 'l list' && _aura_pkg Slq ; } ||
{ _arch_incomp 'l list' && _aura_pkg Slq ; } ||
compopt +o default;;
Q)
{ _aura_incomp 'g groups' && _aura_pkg Qg sort; } ||
{ _aura_incomp 'p file' && _aura_file; } ||
{ _aura_incomp 's search' && compopt +o default; } ||
{ _aura_incomp 'u upgrades' && compopt +o default; } ||
_aura_incomp 'o owns' ||
{ _arch_incomp 'g groups' && _aura_pkg Qg sort; } ||
{ _arch_incomp 'p file' && _aura_file; } ||
{ _arch_incomp 's search' && compopt +o default; } ||
{ _arch_incomp 'u upgrades' && compopt +o default; } ||
_arch_incomp 'o owns' ||
_aura_pkg Qq;;
S)
{ _aura_incomp 'g groups' && _aura_pkg Sg; } ||
{ _aura_incomp 'l list' && _aura_repo_list; } ||
{ _aura_incomp 's search' && compopt +o default; } ||
{ _arch_incomp 'g groups' && _aura_pkg Sg; } ||
{ _arch_incomp 'l list' && _aura_repo_list; } ||
{ _arch_incomp 's search' && compopt +o default; } ||
_aura_pkg Slq;;
U)
_aura_file;;
Expand Down

0 comments on commit 4805a1e

Please sign in to comment.