| 1 |
# |
| 2 |
# Copyright 2013 Allison Karlitskaya |
| 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 |
__app() { |
| 27 |
local gapplication_binary |
| 28 |
gapplication_binary="$1" |
| 29 |
|
| 30 |
case "${COMP_CWORD}" in |
| 31 |
1) |
| 32 |
# shellcheck disable=SC2207 |
| 33 |
COMPREPLY=($(compgen -W "help version list-apps launch action list-actions" -- "${COMP_WORDS[1]}")) |
| 34 |
return 0 |
| 35 |
;; |
| 36 |
|
| 37 |
2) |
| 38 |
case "${COMP_WORDS[1]}" in |
| 39 |
launch|action|list-actions) |
| 40 |
# shellcheck disable=SC2207 |
| 41 |
COMPREPLY=($(compgen -W "$("$gapplication_binary" list-apps)" -- "${COMP_WORDS[2]}")) |
| 42 |
return 0 |
| 43 |
;; |
| 44 |
|
| 45 |
*) |
| 46 |
COMPREPLY=() |
| 47 |
return 0 |
| 48 |
;; |
| 49 |
esac |
| 50 |
;; |
| 51 |
esac |
| 52 |
|
| 53 |
# Otherwise, what we will do is based on the command in ${COMP_WORDS[1]} |
| 54 |
case "${COMP_WORDS[1]}" in |
| 55 |
action) |
| 56 |
# Word 3 is the action name. This is the only one we can help with. |
| 57 |
if [ "${COMP_CWORD}" == 3 ]; then |
| 58 |
# shellcheck disable=SC2207 |
| 59 |
COMPREPLY=($(compgen -W "$("$gapplication_binary" list-actions "${COMP_WORDS[2]}")" -- "${COMP_WORDS[3]}")) |
| 60 |
return 0 |
| 61 |
else |
| 62 |
COMPREPLY=() |
| 63 |
return 0 |
| 64 |
fi |
| 65 |
;; |
| 66 |
launch) |
| 67 |
# Filenames... |
| 68 |
# shellcheck disable=SC2207 |
| 69 |
COMPREPLY=($(compgen -A file "${COMP_WORDS[COMP_CWORD]}")) |
| 70 |
return 0 |
| 71 |
;; |
| 72 |
*) |
| 73 |
# Nothing else should be out this far... |
| 74 |
COMPREPLY=() |
| 75 |
return 0 |
| 76 |
esac |
| 77 |
} |
| 78 |
|
| 79 |
#################################################################################################### |
| 80 |
|
| 81 |
complete -F __app gapplication |