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 "${lopts}" -- $cur ) )
90 COMPREPLY=( $( compgen -W "${opts} ${lopts}" -- $cur ) )
96 opts="-h -v -q -l -s -t -f -a -w"
98 lopts="--help --verbose --quiet --latest --stop --test --server --resetserver
99 --on-server --skip-scan --no-tarball --force --all --wiki"
113 __complete_install() {
115 lopts="--help --verbose --quiet --all"
129 __complete_update() {
130 opts="-h -c -v -q -b -i -I -e -w"
131 lopts="--help --create-metadata --verbose --quiet --buildreport
132 --interactive --icons --editor --wiki --pretty --clean --delete-unknown"
141 __complete_publish() {
143 lopts="--help --verbose --quiet"
149 __apk_vercode unsigned
152 __apk_package unsigned
157 __complete_checkupdates() {
159 lopts="--help --verbose --quiet --auto --autoonly --commit --gplay"
170 __complete_import() {
171 opts="-h -u -s -r -q"
172 lopts="--help --url --subdir --repo --rev --quiet"
174 -u|--url|-r|--repo|-s|--subdir|--rev) return 0;;
179 __complete_readmeta() {
181 lopts="--help --verbose --quiet"
185 __complete_rewritemeta() {
187 lopts="--help --verbose --quiet"
200 lopts="--help --verbose --quiet --pedantic"
211 __complete_scanner() {
213 lopts="--help --verbose --quiet --nosvn"
227 __complete_verify() {
229 lopts="--help --verbose --quiet"
245 lopts="--help --verbose --quiet --download"
249 __complete_server() {
251 lopts="--help --identity-file --verbose --quiet update"
257 lopts="--help --verbose --quiet --distinguished-name --keystore
258 --repo-keyalias --android-home --no-prompt"
265 cmds=" build init install update publish checkupdates import \
266 readmeta rewritemeta lint scanner verify stats server "
268 for c in $cmds; do eval "_fdroid_${c} () {
269 local cur prev opts lopts
273 [[ $cmds == *\ $cmd\ * ]] && _fdroid_${cmd} || {
274 (($COMP_CWORD == 1)) && COMPREPLY=( $( compgen -W "${cmds}" -- $cmd ) )
282 complete -F _fdroid fdroid
283 complete -F _fd-commit fd-commit