1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-04 14:30:11 +01:00
fdroidserver/completion/bash-completion

286 lines
5.5 KiB
Plaintext
Raw Normal View History

2013-10-25 21:30:00 +02:00
#!/bin/bash
2013-07-14 19:09:31 +02:00
#
2013-12-30 17:15:27 +01:00
# bash-completion - part of the FDroid server tools
2014-02-19 01:22:38 +01:00
# Bash completion for the fdroid main tools
2013-07-14 19:09:31 +02:00
#
# Copyright (C) 2013, 2014 Daniel Martí <mvdan@mvdan.cc>
2013-12-30 17:15:27 +01:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2013-12-31 10:17:49 +01:00
# 'fdroid' is completed automatically, but aliases to it are not.
# For instance, to alias 'fd' to 'fdroid' and have competion available:
2013-07-14 19:09:31 +02:00
#
# alias fd='fdroid'
# complete -F _fdroid fd
2013-07-14 19:09:31 +02:00
#
# One can use completion on aliased subcommands as follows:
#
# alias fbuild='fdroid build'
# complete -F _fdroid_build fbuild
2013-07-14 19:09:31 +02:00
__fdroid_init() {
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
2013-07-14 19:09:31 +02:00
(( $# >= 1 )) && __complete_${1}
2013-07-14 19:09:31 +02:00
}
__package() {
files=( metadata/*.txt )
files=( ${files[@]#metadata/} )
files=${files[@]%.txt}
COMPREPLY=( $( compgen -W "$files" -- $cur ) )
}
__apk_package() {
files=( ${1}/*.apk )
[ -f "${files[0]}" ] || return
files=( ${files[@]#*/} )
files=${files[@]%_*}
COMPREPLY=( $( compgen -W "$files" -- $cur ) )
}
__apk_vercode() {
2013-12-31 10:17:49 +01:00
local p=${cur:0:-1}
2013-12-11 18:35:58 +01:00
files=( ${1}/${p}_*.apk )
[ -f "${files[0]}" ] || return
2013-12-11 18:35:58 +01:00
files=( ${files[@]#*_} )
files=${files[@]%.apk}
COMPREPLY=( $( compgen -P "${p}:" -W "$files" -- $cur ) )
}
2013-07-14 19:09:31 +02:00
__vercode() {
local p v
echo $cur | IFS=':' read p v
COMPREPLY=( $( compgen -P "${p}:" -W "$( while read line; do
if [[ "$line" == "Build Version:"* ]]
then
line="${line#*,}"
printf "${line%%,*} "
elif [[ "$line" == "Build:"* ]]
then
line="${line#*,}"
printf "${line%%,*} "
fi
done < "metadata/${p}.txt" )" -- $cur ) )
2013-07-14 19:09:31 +02:00
}
__complete_options() {
case "${cur}" in
--*)
COMPREPLY=( $( compgen -W "${lopts}" -- $cur ) )
return 0;;
*)
COMPREPLY=( $( compgen -W "${opts} ${lopts}" -- $cur ) )
return 0;;
esac
2013-07-14 19:09:31 +02:00
}
__complete_build() {
opts="-h -v -q -l -s -t -f -a -w"
lopts="--help --verbose --quiet --latest --stop --test --server --resetserver
--on-server --skip-scan --no-tarball --force --all --wiki"
case "${cur}" in
2013-12-19 23:06:57 +01:00
-*)
__complete_options
return 0;;
*:*)
__vercode
return 0;;
*)
__package
return 0;;
esac
2013-07-14 19:09:31 +02:00
}
2013-12-11 18:35:58 +01:00
__complete_install() {
2014-05-06 16:19:05 +02:00
opts="-h -v -q"
lopts="--help --verbose --quiet --all"
2013-12-11 18:35:58 +01:00
case "${cur}" in
-*)
__complete_options
return 0;;
*:)
__apk_vercode repo
2013-12-11 18:35:58 +01:00
return 0;;
*)
__apk_package repo
2013-12-11 18:35:58 +01:00
return 0;;
esac
}
2013-07-14 19:09:31 +02:00
__complete_update() {
opts="-h -c -v -q -b -i -I -e -w"
lopts="--help --create-metadata --verbose --quiet --buildreport
--interactive --icons --editor --wiki --pretty --clean --delete-unknown"
case "${prev}" in
-e|--editor)
_filedir
return 0;;
esac
__complete_options
2013-07-14 19:09:31 +02:00
}
__complete_publish() {
2014-05-06 16:19:05 +02:00
opts="-h -v -q"
lopts="--help --verbose --quiet"
case "${cur}" in
-*)
__complete_options
return 0;;
*:)
__apk_vercode unsigned
return 0;;
*)
__apk_package unsigned
return 0;;
esac
2013-07-14 19:09:31 +02:00
}
__complete_checkupdates() {
2014-05-06 16:19:05 +02:00
opts="-h -v -q"
lopts="--help --verbose --quiet --auto --autoonly --commit --gplay"
2013-12-11 19:37:38 +01:00
case "${cur}" in
-*)
__complete_options
return 0;;
*)
__package
return 0;;
esac
2013-07-14 19:09:31 +02:00
}
__complete_import() {
2014-04-29 08:41:48 +02:00
opts="-h -u -s -r -q"
lopts="--help --url --subdir --repo --rev --quiet"
case "${prev}" in
-u|--url|-r|--repo|-s|--subdir|--rev) return 0;;
esac
__complete_options
2013-07-14 19:09:31 +02:00
}
2014-02-05 09:21:28 +01:00
__complete_readmeta() {
2014-05-06 16:19:05 +02:00
opts="-h -v -q"
lopts="--help --verbose --quiet"
2014-02-15 00:00:05 +01:00
__complete_options
2014-02-05 09:21:28 +01:00
}
2013-07-14 19:09:31 +02:00
__complete_rewritemeta() {
2014-05-06 16:19:05 +02:00
opts="-h -v -q"
lopts="--help --verbose --quiet"
2013-12-19 22:59:32 +01:00
case "${cur}" in
-*)
__complete_options
return 0;;
*)
__package
return 0;;
esac
2013-07-14 19:09:31 +02:00
}
2014-01-03 00:12:42 +01:00
__complete_lint() {
2014-05-06 16:19:05 +02:00
opts="-h -v -q -p"
lopts="--help --verbose --quiet --pedantic"
2014-01-03 00:12:42 +01:00
case "${cur}" in
-*)
__complete_options
return 0;;
*)
__package
return 0;;
esac
}
2013-07-14 19:09:31 +02:00
__complete_scanner() {
2014-05-06 16:19:05 +02:00
opts="-h -v -q"
lopts="--help --verbose --quiet --nosvn"
2013-12-19 23:06:57 +01:00
case "${cur}" in
-*)
__complete_options
return 0;;
*:)
__vercode
return 0;;
*)
__package
return 0;;
esac
2013-07-14 19:09:31 +02:00
}
__complete_verify() {
2014-05-06 16:19:05 +02:00
opts="-h -v -q -p"
lopts="--help --verbose --quiet"
2013-12-19 23:14:22 +01:00
case "${cur}" in
-*)
__complete_options
return 0;;
*:)
__vercode
return 0;;
*)
__package
return 0;;
esac
}
2013-07-14 19:09:31 +02:00
__complete_stats() {
2014-05-06 16:19:05 +02:00
opts="-h -v -q -d"
lopts="--help --verbose --quiet --download"
__complete_options
2013-07-14 19:09:31 +02:00
}
__complete_server() {
opts="-h -i -v -q"
lopts="--help --identity-file --verbose --quiet update"
__complete_options
2013-07-14 19:09:31 +02:00
}
__complete_init() {
2014-05-06 16:19:05 +02:00
opts="-h -v -q -d"
2014-06-12 21:51:33 +02:00
lopts="--help --verbose --quiet --distinguished-name --keystore
--repo-keyalias --android-home --no-prompt"
__complete_options
}
2013-07-14 19:09:31 +02:00
_fdroid() {
2013-12-31 10:17:49 +01:00
local cmd cmds
cmd=${COMP_WORDS[1]}
cmds=" build init install update publish checkupdates import \
2014-02-05 09:21:28 +01:00
readmeta rewritemeta lint scanner verify stats server "
2013-07-14 19:09:31 +02:00
for c in $cmds; do eval "_fdroid_${c} () {
2013-12-31 10:17:49 +01:00
local cur prev opts lopts
__fdroid_init ${c};
}"; done
2013-07-14 19:09:31 +02:00
[[ $cmds == *\ $cmd\ * ]] && _fdroid_${cmd} || {
(($COMP_CWORD == 1)) && COMPREPLY=( $( compgen -W "${cmds}" -- $cmd ) )
}
2013-07-14 19:09:31 +02:00
}
2013-11-03 11:53:20 +01:00
_fd-commit() {
__package
}
2013-07-14 19:09:31 +02:00
complete -F _fdroid fdroid
2013-11-03 11:53:20 +01:00
complete -F _fd-commit fd-commit
2013-07-14 19:09:31 +02:00
return 0