forked from renatosilva/pactoys
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpacboy.completion
91 lines (84 loc) · 3.09 KB
/
pacboy.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Bash completion for Pacboy
# Copyright (C) 2015 Renato Silva
# Licensed under BSD
_pacboy_repositories() {
local repositories
local current="${1}"
local suffix="${2}"
for database in /var/lib/pacman/sync/*.db; do
database="${database##*/}"
repositories="${repositories} ${database%.db}${suffix}"
done
COMPREPLY+=($(compgen -W "${repositories}" -- ${current}))
__ltrim_colon_completions "${current}"
}
_pacboy() {
local commands='sync update refresh find packages files info origin remove'
local current command
local debug='enabled'
local help='enabled'
local repository
_get_comp_words_by_ref -n : -c current
COMPREPLY=()
# Commands
for argument in "${COMP_WORDS[@]}"; do
if [[ "${argument}" != "${current}" ]]; then
case "${argument}" in
help) unset help; continue ;;
debug) unset debug; continue ;;
esac
fi
test -n "${command}" && continue
for valid_command in ${commands}; do
if [[ "${argument}" = "${valid_command}" ]]; then
command="${argument}"
break
fi
done
done
COMPREPLY+=($(compgen -W "${help:+help}" -- ${current}))
COMPREPLY+=($(compgen -W "${debug:+debug}" -- ${current}))
if [[ -z "${command}" ]]; then
COMPREPLY+=($(compgen -W "${commands}" -- ${current}))
COMPREPLY=("${COMPREPLY[@]/%/ }")
return
fi
# Repositories
if [[ "${command}" = packages ]]; then
_pacboy_repositories "${current}"
COMPREPLY=("${COMPREPLY[@]/%/ }")
return
fi
if [[ "${command}" = sync ]]; then
if [[ "${current}" != *::* ]]
then _pacboy_repositories "${current}" ::
else repository="${current%::*}"
current="${current##*::}"
fi
fi
# Packages
if [[ "${command}" =~ ^(sync|files|info|remove)$ ]]; then
local packages=$(cat /var/cache/pacboy/${repository:-*}.packages 2>/dev/null)
if [[ -z "${packages}" ]]; then
local mingw_suffix="${MSYSTEM/MSYS/:m}"
local msys_suffix="${MSYSTEM/MINGW*/:}"
for package in $(pacman --sync --list --quiet ${repository}); do
case "${package}" in
mingw-w64-x86_64-*) package="${package/mingw-w64-x86_64-/}${mingw_suffix}" ;;
mingw-w64-i686-*) package="${package/mingw-w64-i686-/}${mingw_suffix}" ;;
*) package="${package}${msys_suffix}"
esac
packages="${packages} ${package}"
done
elif [[ "${MSYSTEM}" = MSYS ]]; then
packages=$(sed -e 's/\([^:]\)$/\1:m/' -e 's/:$//' <<<"${packages}")
fi
COMPREPLY+=($(compgen -W "${packages}" -- ${current}))
__ltrim_colon_completions "${current}"
fi
if [[ "${current}" != *: || "${COMPREPLY[@]}" != : ]]; then
COMPREPLY=("${COMPREPLY[@]/%/ }")
COMPREPLY=("${COMPREPLY[@]/:: /::}")
fi
}
complete -F _pacboy -o nospace -o bashdefault -o default pacboy