Skip to content

Commit

Permalink
[eos-packagelist] faster bash completion
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-192 committed Aug 4, 2024
1 parent 8abffc9 commit f039f0a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
8 changes: 6 additions & 2 deletions eos-packagelist/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Contributor : Sravan Pannala <sradjoker@endeavouros.com>

pkgname=eos-packagelist
pkgver=2.3
pkgver=2.3.1
pkgrel=1
pkgdesc="An application to gather and optionally install package lists from the EndeavourOS installer"
arch=('any')
Expand All @@ -14,9 +14,13 @@ source=(
eos-packagelist.bash-completion
)
sha256sums=('0f421de391d125c437ec86af584db60fd1f71a09c8b26506d1b60620ac429270'
'73a68cde33cd2cbbba0ebf7c39f10dc8993e73f3d40debd9e4899d4e84a1ca07')
'097c09ef22e981ec9dc6e1a8b6e5172c2558b0c52fe4dbd9949a55b448f8bdfb')

package() {
local profiles=eos-packagelist.profiles
eos-packagelist --list | sort -u > $profiles

install -Dm0755 "$srcdir/eos-packagelist" "$pkgdir/usr/bin/eos-packagelist"
install -Dm0644 eos-packagelist.bash-completion "$pkgdir/usr/share/bash-completion/completions/eos-packagelist"
install -Dm0644 $profiles "$pkgdir/etc/$profiles"
}
31 changes: 14 additions & 17 deletions eos-packagelist/eos-packagelist.bash-completion
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# bash completion for eos-packagelist -*- shell-script -*-

_eos-packagelist_complete() {
local IFS=$'\n' # handles spaces in names!
local IFS="$newline" # handles spaces in names!
COMPREPLY=($(compgen -W "$1" -- "$cur"))
[[ $COMPREPLY == *= ]] && compopt -o nospace
compopt -o nosort

# quote the selectable items but not flags
local item ix
# quote the profiles but not flags
local profile ix
local -r count=${#COMPREPLY[@]}
for ((ix=0; ix < count; ix++)) ; do
item="${COMPREPLY[$ix]}"
case "$item" in
profile="${COMPREPLY[$ix]}"
case "$profile" in
-*) ;;
*) COMPREPLY[$ix]="'$item'" ;;
*) [ "${profile// /}" != "$profile" ] && COMPREPLY[$ix]="'$profile'" ;;
esac
done
}
Expand All @@ -23,32 +23,29 @@ _eos-packagelist_()
local cur prev #words cword split
_init_completion -s || return

local -r newline=$'\n'

# eos-packagelist options
local options=(
--help -h --list --arch --install
)

# architectures supported by eos-packagelist
local architectures=(
x86_64 aarch64 armv7h
--help -h --list --install
)
# eos-packagelist profiles
local -r profiles=$(< /etc/eos-packagelist.profiles)

# Handle options that need sub-options.

case "$prev" in
--arch)
_eos-packagelist_complete "$(printf "%s\n" "${architectures[@]}")"
;;
*)
# Handle all top-level parameters.
local -r options2=$(printf "%s\n" "${options[@]}")
case "$cur" in
-*)
# Any option.
_eos-packagelist_complete "$(printf "%s\n" "${options[@]}")"
_eos-packagelist_complete "$options2"
;;
*)
# Non-option parameters.
_eos-packagelist_complete "$(printf "%s\n" "${options[@]}"; eos-packagelist --list | sort)"
_eos-packagelist_complete "$options2$newline$profiles"
;;
esac
;;
Expand Down

0 comments on commit f039f0a

Please sign in to comment.