| 1 |
# |
| 2 |
# Copyright 2012 Red Hat, Inc. |
| 3 |
# |
| 4 |
# This library is free software; you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU Lesser General Public License as |
| 6 |
# published by the Free Software Foundation; either version 2.1 of the |
| 7 |
# licence, or (at your option) any later version. |
| 8 |
# |
| 9 |
# This is distributed in the hope that it will be useful, but WITHOUT |
| 10 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| 12 |
# License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU Lesser General Public License |
| 15 |
# along with this library; if not, see <http://www.gnu.org/licenses/>. |
| 16 |
# |
| 17 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 18 |
|
| 19 |
# shellcheck shell=bash |
| 20 |
|
| 21 |
# Check for bash |
| 22 |
[ -z "$BASH_VERSION" ] && return |
| 23 |
|
| 24 |
#################################################################################################### |
| 25 |
|
| 26 |
__gresource() { |
| 27 |
local choices coffset gresource_binary |
| 28 |
gresource_binary="$1" |
| 29 |
|
| 30 |
if [ "${COMP_CWORD}" -gt 2 ]; then |
| 31 |
if [ "${COMP_WORDS[1]}" = --section ]; then |
| 32 |
coffset=2 |
| 33 |
else |
| 34 |
coffset=0 |
| 35 |
fi |
| 36 |
else |
| 37 |
coffset=0 |
| 38 |
fi |
| 39 |
|
| 40 |
case "$((COMP_CWORD-coffset))" in |
| 41 |
1) |
| 42 |
choices=$'--section \nhelp \nsections \nlist \ndetails \nextract ' |
| 43 |
;; |
| 44 |
|
| 45 |
2) |
| 46 |
case "${COMP_WORDS[$((coffset+1))]}" in |
| 47 |
--section) |
| 48 |
return 0 |
| 49 |
;; |
| 50 |
|
| 51 |
help) |
| 52 |
choices=$'sections\nlist\ndetails\nextract' |
| 53 |
;; |
| 54 |
|
| 55 |
sections|list|details|extract) |
| 56 |
# shellcheck disable=SC2207 |
| 57 |
COMPREPLY=($(compgen -f -- "${COMP_WORDS[${COMP_CWORD}]}")) |
| 58 |
return 0 |
| 59 |
;; |
| 60 |
esac |
| 61 |
;; |
| 62 |
|
| 63 |
3) |
| 64 |
case "${COMP_WORDS[$((coffset+1))]}" in |
| 65 |
list|details|extract) |
| 66 |
choices="$("$gresource_binary" list "${COMP_WORDS[$((coffset+2))]}" 2> /dev/null | sed -e 's.$. .')" |
| 67 |
;; |
| 68 |
esac |
| 69 |
;; |
| 70 |
esac |
| 71 |
|
| 72 |
local IFS=$'\n' |
| 73 |
# shellcheck disable=SC2207 |
| 74 |
COMPREPLY=($(compgen -W "${choices}" -- "${COMP_WORDS[${COMP_CWORD}]}")) |
| 75 |
} |
| 76 |
|
| 77 |
#################################################################################################### |
| 78 |
|
| 79 |
complete -o nospace -F __gresource gresource |