3 # bash-completion - part of the FDroid server tools
4 # Bash completion for the fdroid main tools
6 # Copyright (C) 2013, 2014 Daniel Martà <mvdan@mvdan.cc>
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # 'fdroid' is completed automatically, but aliases to it are not.
22 # For instance, to alias 'fd' to 'fdroid' and have competion available:
25 # complete -F _fdroid fd
27 # One can use completion on aliased subcommands as follows:
29 # alias fbuild='fdroid build'
30 # complete -F _fdroid_build fbuild
34 cur="${COMP_WORDS[COMP_CWORD]}"
35 prev="${COMP_WORDS[COMP_CWORD-1]}"
37 (( $# >= 1 )) && __complete_${1}
41 files=( metadata/*.txt )
42 files=( ${files[@]#metadata/} )
43 files=${files[@]%.txt}
44 COMPREPLY=( $( compgen -W "$files" -- $cur ) )
49 [ -f "${files[0]}" ] || return
51 files=( ${files[@]#*/} )
53 COMPREPLY=( $( compgen -W "$files" -- $cur ) )
59 files=( ${1}/${p}_*.apk )
60 [ -f "${files[0]}" ] || return
62 files=( ${files[@]#*_} )
63 files=${files[@]%.apk}
64 COMPREPLY=( $( compgen -P "${p}:" -W "$files" -- $cur ) )
69 echo $cur | IFS=':' read p v
71 COMPREPLY=( $( compgen -P "${p}:" -W "$( while read line; do
72 if [[ "$line" == "Build Version:"* ]]
76 elif [[ "$line" == "Build:"* ]]
81 done < "metadata/${p}.txt" )" -- $cur ) )
84 __complete_options() {
87 COMPREPLY=( $( compgen -W "--help ${lopts}" -- $cur ) )
90 COMPREPLY=( $( compgen -W "-h ${opts} --help ${lopts}" -- $cur ) )
96 opts="-v -q -l -s -t -f -a -w"
98 lopts="--verbose --quiet --latest --stop --test --server --resetserver
99 --on-server --skip-scan --no-tarball --force --all --wiki"
113 __complete_install() {
115 lopts="--verbose --quiet --all"
129 __complete_update() {
130 opts="-c -v -q -b -i -I -e -w"
131 lopts="--create-metadata --verbose --quiet --buildreport
132 --interactive --icons --editor --wiki --pretty --clean --delete-unknown
142 __complete_publish() {
144 lopts="--verbose --quiet"
150 __apk_vercode unsigned
153 __apk_package unsigned
158 __complete_checkupdates() {
160 lopts="--verbose --quiet --auto --autoonly --commit --gplay"
171 __complete_import() {
173 lopts="--url --subdir --repo --rev --quiet"
175 -u|--url|-r|--repo|-s|--subdir|--rev) return 0;;
180 __complete_readmeta() {
182 lopts="--verbose --quiet"
186 __complete_rewritemeta() {
188 lopts="--verbose --quiet"
201 lopts="--verbose --quiet --pedantic"
212 __complete_scanner() {
214 lopts="--verbose --quiet --nosvn"
228 __complete_verify() {
230 lopts="--verbose --quiet"
246 lopts="--verbose --quiet --download"
250 __complete_server() {
252 lopts="--identity-file --verbose --quiet update"
256 __complete_signindex() {
264 lopts="--verbose --quiet --distinguished-name --keystore
265 --repo-keyalias --android-home --no-prompt"
272 cmds=" build init install update publish checkupdates import \
273 readmeta rewritemeta lint scanner verify stats server signindex "
275 for c in $cmds; do eval "_fdroid_${c} () {
276 local cur prev opts lopts
280 [[ $cmds == *\ $cmd\ * ]] && _fdroid_${cmd} || {
281 (($COMP_CWORD == 1)) && COMPREPLY=( $( compgen -W "${cmds}" -- $cmd ) )
289 complete -F _fdroid fdroid
290 complete -F _fd-commit fd-commit