chiark / gitweb /
Complete update --nosign
[fdroidserver.git] / completion / bash-completion
1 #!/bin/bash
2 #
3 # bash-completion - part of the FDroid server tools
4 # Bash completion for the fdroid main tools
5 #
6 # Copyright (C) 2013, 2014 Daniel Martí <mvdan@mvdan.cc>
7 #
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.
12 #
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.
17 #
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/>.
20
21 # 'fdroid' is completed automatically, but aliases to it are not.
22 # For instance, to alias 'fd' to 'fdroid' and have competion available:
23 #
24 #       alias fd='fdroid'
25 #       complete -F _fdroid fd
26 #
27 # One can use completion on aliased subcommands as follows:
28 #
29 #       alias fbuild='fdroid build'
30 #       complete -F _fdroid_build fbuild
31
32 __fdroid_init() {
33         COMPREPLY=()
34         cur="${COMP_WORDS[COMP_CWORD]}"
35         prev="${COMP_WORDS[COMP_CWORD-1]}"
36
37         (( $# >= 1 )) && __complete_${1}
38 }
39
40 __package() {
41         files=( metadata/*.txt )
42         files=( ${files[@]#metadata/} )
43         files=${files[@]%.txt}
44         COMPREPLY=( $( compgen -W "$files" -- $cur ) )
45 }
46
47 __apk_package() {
48         files=( ${1}/*.apk )
49         [ -f "${files[0]}" ] || return
50
51         files=( ${files[@]#*/} )
52         files=${files[@]%_*}
53         COMPREPLY=( $( compgen -W "$files" -- $cur ) )
54 }
55
56 __apk_vercode() {
57         local p=${cur:0:-1}
58
59         files=( ${1}/${p}_*.apk )
60         [ -f "${files[0]}" ] || return
61
62         files=( ${files[@]#*_} )
63         files=${files[@]%.apk}
64         COMPREPLY=( $( compgen -P "${p}:" -W "$files" -- $cur ) )
65 }
66
67 __vercode() {
68         local p v
69         echo $cur | IFS=':' read p v
70
71         COMPREPLY=( $( compgen -P "${p}:" -W "$( while read line; do
72                 if [[ "$line" == "Build Version:"* ]]
73                 then
74                         line="${line#*,}"
75                         printf "${line%%,*} "
76                 elif [[ "$line" == "Build:"* ]]
77                 then
78                         line="${line#*,}"
79                         printf "${line%%,*} "
80                 fi
81                 done < "metadata/${p}.txt" )" -- $cur ) )
82 }
83
84 __complete_options() {
85         case "${cur}" in
86                 --*)
87                         COMPREPLY=( $( compgen -W "--help ${lopts}" -- $cur ) )
88                         return 0;;
89                 *)
90                         COMPREPLY=( $( compgen -W "-h ${opts} --help ${lopts}" -- $cur ) )
91                         return 0;;
92         esac
93 }
94
95 __complete_build() {
96         opts="-v -q -l -s -t -f -a -w"
97
98         lopts="--verbose --quiet --latest --stop --test --server --resetserver
99  --on-server --skip-scan --no-tarball --force --all --wiki"
100         case "${cur}" in
101                 -*)
102                         __complete_options
103                         return 0;;
104                 *:*)
105                         __vercode
106                         return 0;;
107                 *)
108                         __package
109                         return 0;;
110         esac
111 }
112
113 __complete_install() {
114         opts="-v -q"
115         lopts="--verbose --quiet --all"
116         case "${cur}" in
117                 -*)
118                         __complete_options
119                         return 0;;
120                 *:)
121                         __apk_vercode repo
122                         return 0;;
123                 *)
124                         __apk_package repo
125                         return 0;;
126         esac
127 }
128
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
133  --nosign"
134         case "${prev}" in
135                 -e|--editor)
136                         _filedir
137                         return 0;;
138         esac
139         __complete_options
140 }
141
142 __complete_publish() {
143         opts="-v -q"
144         lopts="--verbose --quiet"
145         case "${cur}" in
146                 -*)
147                         __complete_options
148                         return 0;;
149                 *:)
150                         __apk_vercode unsigned
151                         return 0;;
152                 *)
153                         __apk_package unsigned
154                         return 0;;
155         esac
156 }
157
158 __complete_checkupdates() {
159         opts="-v -q"
160         lopts="--verbose --quiet --auto --autoonly --commit --gplay"
161         case "${cur}" in
162                 -*)
163                         __complete_options
164                         return 0;;
165                 *)
166                         __package
167                         return 0;;
168         esac
169 }
170
171 __complete_import() {
172         opts="-u -s -r -q"
173         lopts="--url --subdir --repo --rev --quiet"
174         case "${prev}" in
175                 -u|--url|-r|--repo|-s|--subdir|--rev) return 0;;
176         esac
177         __complete_options
178 }
179
180 __complete_readmeta() {
181         opts="-v -q"
182         lopts="--verbose --quiet"
183         __complete_options
184 }
185
186 __complete_rewritemeta() {
187         opts="-v -q"
188         lopts="--verbose --quiet"
189         case "${cur}" in
190                 -*)
191                         __complete_options
192                         return 0;;
193                 *)
194                         __package
195                         return 0;;
196         esac
197 }
198
199 __complete_lint() {
200         opts="-v -q -p"
201         lopts="--verbose --quiet --pedantic"
202         case "${cur}" in
203                 -*)
204                         __complete_options
205                         return 0;;
206                 *)
207                         __package
208                         return 0;;
209         esac
210 }
211
212 __complete_scanner() {
213         opts="-v -q"
214         lopts="--verbose --quiet --nosvn"
215         case "${cur}" in
216                 -*)
217                         __complete_options
218                         return 0;;
219                 *:)
220                         __vercode
221                         return 0;;
222                 *)
223                         __package
224                         return 0;;
225         esac
226 }
227
228 __complete_verify() {
229         opts="-v -q -p"
230         lopts="--verbose --quiet"
231         case "${cur}" in
232                 -*)
233                         __complete_options
234                         return 0;;
235                 *:)
236                         __vercode
237                         return 0;;
238                 *)
239                         __package
240                         return 0;;
241         esac
242 }
243
244 __complete_stats() {
245         opts="-v -q -d"
246         lopts="--verbose --quiet --download"
247         __complete_options
248 }
249
250 __complete_server() {
251         opts="-i -v -q"
252         lopts="--identity-file --verbose --quiet update"
253         __complete_options
254 }
255
256 __complete_signindex() {
257         opts="-v -q"
258         lopts="--verbose"
259         __complete_options
260 }
261
262 __complete_init() {
263         opts="-v -q -d"
264         lopts="--verbose --quiet --distinguished-name --keystore
265  --repo-keyalias --android-home --no-prompt"
266         __complete_options
267 }
268
269 _fdroid() {
270         local cmd cmds
271         cmd=${COMP_WORDS[1]}
272         cmds=" build init install update publish checkupdates import \
273 readmeta rewritemeta lint scanner verify stats server signindex "
274
275         for c in $cmds; do eval "_fdroid_${c} () {
276                 local cur prev opts lopts
277                 __fdroid_init ${c};
278         }"; done
279
280         [[ $cmds == *\ $cmd\ * ]] && _fdroid_${cmd} || {
281                 (($COMP_CWORD == 1)) && COMPREPLY=( $( compgen -W "${cmds}" -- $cmd ) )
282         }
283 }
284
285 _fd-commit() {
286         __package
287 }
288
289 complete -F _fdroid fdroid
290 complete -F _fd-commit fd-commit
291
292 return 0