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}
42 files=( metadata/*.$ext )
43 files=( ${files[@]#metadata/} )
44 files=${files[@]%.$ext}
49 files="$(__by_ext txt) $(__by_ext yaml) $(__by_ext json) $(__by_ext xml)"
50 COMPREPLY=( $( compgen -W "$files" -- $cur ) )
55 [ -f "${files[0]}" ] || return
57 files=( ${files[@]#*/} )
59 COMPREPLY=( $( compgen -W "$files" -- $cur ) )
65 files=( ${1}/${p}_*.apk )
66 [ -f "${files[0]}" ] || return
68 files=( ${files[@]#*_} )
69 files=${files[@]%.apk}
70 COMPREPLY=( $( compgen -P "${p}:" -W "$files" -- $cur ) )
75 echo $cur | IFS=':' read p v
77 COMPREPLY=( $( compgen -P "${p}:" -W "$( while read line; do
78 if [[ "$line" == "Build Version:"* ]]
82 elif [[ "$line" == "Build:"* ]]
87 done < "metadata/${p}.txt" )" -- $cur ) )
90 __complete_options() {
93 COMPREPLY=( $( compgen -W "--help --version ${lopts}" -- $cur ) )
96 COMPREPLY=( $( compgen -W "-h ${opts} --help --version ${lopts}" -- $cur ) )
102 opts="-v -q -l -s -t -f -a -w"
104 lopts="--verbose --quiet --latest --stop --test --server --resetserver
105 --on-server --skip-scan --no-tarball --force --all --wiki --no-refresh"
119 __complete_install() {
121 lopts="--verbose --quiet --all"
135 __complete_update() {
136 opts="-c -v -q -b -i -I -e -w"
137 lopts="--create-metadata --verbose --quiet --buildreport
138 --interactive --icons --editor --wiki --pretty --clean --delete-unknown
139 --nosign --use-date-from-apk"
148 __complete_publish() {
150 lopts="--verbose --quiet"
156 __apk_vercode unsigned
159 __apk_package unsigned
164 __complete_checkupdates() {
166 lopts="--verbose --quiet --auto --autoonly --commit --gplay"
177 __complete_import() {
179 lopts="--url --subdir --rev --quiet"
181 -u|--url|-s|--subdir|--rev) return 0;;
186 __complete_readmeta() {
188 lopts="--verbose --quiet"
192 __complete_rewritemeta() {
194 lopts="--verbose --quiet --list"
207 lopts="--verbose --quiet"
218 __complete_scanner() {
220 lopts="--verbose --quiet"
234 __complete_verify() {
236 lopts="--verbose --quiet"
252 lopts="--verbose --quiet --download"
256 __complete_server() {
258 lopts="--identity-file --local-copy-dir --sync-from-local-copy-dir
259 --verbose --quiet --no-checksum update"
263 __complete_signindex() {
271 lopts="--verbose --quiet --distinguished-name --keystore
272 --repo-keyalias --android-home --no-prompt"
276 __cmds=" build init install update publish checkupdates import readmeta \
277 rewritemeta lint scanner verify stats server signindex "
280 eval "_fdroid_${c} () {
281 local cur prev opts lopts
290 [[ $__cmds == *\ $cmd\ * ]] && _fdroid_${cmd} || {
291 (($COMP_CWORD == 1)) && COMPREPLY=( $( compgen -W "${__cmds}" -- $cmd ) )
299 complete -F _fdroid fdroid
300 complete -F _fd-commit fd-commit