forked from AFK-OS/una
-
Notifications
You must be signed in to change notification settings - Fork 0
/
una-completion
25 lines (20 loc) · 1004 Bytes
/
una-completion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#/usr/bin/env bash
set +e
_completions() {
SUGGESTIONS=()
if [[ "$COMP_CWORD" == 1 ]]; then
SUGGESTIONS=('install' 'upgrade' 'remove' \
'update' 'help' 'list' 'info' 'search' )
elif [[ "$COMP_CWORD" -ge 2 ]] && [[ "${COMP_WORDS[1]}" == remove ]]; then
for pkg in $(dpkg-query --show --showformat '${Package} '); do
SUGGESTIONS+=("${pkg}")
done
elif [[ "$COMP_CWORD" -ge 2 ]] && ( [[ "${COMP_WORDS[1]}" == install ]] \
|| [[ "${COMP_WORDS[1]}" == search ]] || [[ "${COMP_WORDS[1]}" == info ]] || [[ "${COMP_WORDS[1]}" == clone ]] ); then
for pkg in $(cat ~/.cache/una/cache | jq -r '.[].Name' | grep "^${COMP_WORDS[$COMP_CWORD]}" || true) $(apt-cache search --names-only "^${COMP_WORDS[$COMP_CWORD]}" 2>/dev/null | sort -d | awk '{print $1}' || true); do
SUGGESTIONS+=("${pkg}")
done
fi
COMPREPLY=($(compgen -W "${SUGGESTIONS[*]}" "${COMP_WORDS[$COMP_CWORD]}"))
}
complete -F _completions -- una