2013-10-25 21:30:00 +02:00
|
|
|
#!/bin/bash
|
2013-07-14 19:09:31 +02:00
|
|
|
#
|
|
|
|
# fdroid completion support.
|
|
|
|
#
|
|
|
|
# 'fdroid' is aliased automatically, but aliases to it are not. For instance,
|
|
|
|
# to alias 'fd' to 'fdroid' and have competion available:
|
|
|
|
#
|
2013-11-03 11:50:44 +01: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:
|
|
|
|
#
|
2013-11-03 11:50:44 +01:00
|
|
|
# alias fbuild='fdroid build'
|
|
|
|
# complete -F _fdroid_build fbuild
|
2013-07-14 19:09:31 +02:00
|
|
|
|
|
|
|
__fdroid_init() {
|
2013-10-29 00:19:33 +01:00
|
|
|
COMPREPLY=()
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
2013-07-14 19:09:31 +02:00
|
|
|
|
2013-10-29 00:19:33 +01:00
|
|
|
(( $# >= 1 )) && __complete_${1}
|
2013-07-14 19:09:31 +02:00
|
|
|
}
|
|
|
|
|
2013-11-18 15:26:57 +01:00
|
|
|
__package() {
|
2013-12-11 17:29:38 +01:00
|
|
|
files=( metadata/*.txt )
|
|
|
|
files=( ${files[@]#metadata/} )
|
2013-11-18 15:26:57 +01:00
|
|
|
files=${files[@]%.txt}
|
|
|
|
COMPREPLY=( $( compgen -W "$files" -- $cur ) )
|
|
|
|
}
|
|
|
|
|
2013-12-19 22:55:17 +01:00
|
|
|
__apk_package() {
|
|
|
|
files=( ${1}/*.apk )
|
|
|
|
[ -f "${files[0]}" ] || return
|
|
|
|
|
|
|
|
files=( ${files[@]#*/} )
|
2013-12-11 17:29:38 +01:00
|
|
|
files=${files[@]%_*}
|
|
|
|
COMPREPLY=( $( compgen -W "$files" -- $cur ) )
|
|
|
|
}
|
|
|
|
|
2013-12-19 22:55:17 +01:00
|
|
|
__apk_vercode() {
|
2013-12-11 18:35:58 +01:00
|
|
|
local p
|
|
|
|
p=${cur:0:-1}
|
|
|
|
|
2013-12-19 22:55:17 +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() {
|
2013-12-11 17:29:38 +01:00
|
|
|
local p
|
|
|
|
p=${cur:0:-1}
|
2013-10-29 00:19:33 +01:00
|
|
|
|
2013-12-11 17:29:38 +01:00
|
|
|
COMPREPLY=( $( compgen -P "${p}:" -W "$( while read line; do
|
2013-10-29 00:19:33 +01:00
|
|
|
if [[ "$line" == "Build Version:"* ]]
|
|
|
|
then
|
|
|
|
line="${line#*,}"
|
|
|
|
printf "${line%%,*} "
|
|
|
|
elif [[ "$line" == "Build:"* ]]
|
|
|
|
then
|
|
|
|
line="${line#*,}"
|
|
|
|
printf "${line%%,*} "
|
|
|
|
fi
|
2013-12-11 17:29:38 +01:00
|
|
|
done < "metadata/${p}.txt" )" -- $cur ) )
|
2013-07-14 19:09:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__complete_options() {
|
2013-10-29 00:19:33 +01:00
|
|
|
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() {
|
2013-10-29 00:19:33 +01:00
|
|
|
opts="-h -v -p -c -l -s -t -f"
|
2013-12-11 17:29:38 +01:00
|
|
|
lopts="--help --verbose --latest --server --resetserver --on-server
|
|
|
|
--force --all"
|
|
|
|
case "${cur}" in
|
|
|
|
*:)
|
2013-10-29 00:19:33 +01:00
|
|
|
__vercode
|
|
|
|
return 0;;
|
2013-12-11 17:29:38 +01:00
|
|
|
*)
|
|
|
|
__package
|
|
|
|
return 0;;
|
2013-10-29 00:19:33 +01:00
|
|
|
esac
|
|
|
|
__complete_options
|
2013-07-14 19:09:31 +02:00
|
|
|
}
|
|
|
|
|
2013-12-11 18:35:58 +01:00
|
|
|
__complete_install() {
|
|
|
|
opts="-h -v"
|
|
|
|
lopts="--help --verbose --all"
|
|
|
|
case "${cur}" in
|
|
|
|
-*)
|
|
|
|
__complete_options
|
|
|
|
return 0;;
|
|
|
|
*:)
|
2013-12-19 22:55:17 +01:00
|
|
|
__apk_vercode repo
|
2013-12-11 18:35:58 +01:00
|
|
|
return 0;;
|
|
|
|
*)
|
2013-12-19 22:55:17 +01:00
|
|
|
__apk_package repo
|
2013-12-11 18:35:58 +01:00
|
|
|
return 0;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2013-07-14 19:09:31 +02:00
|
|
|
__complete_update() {
|
2013-10-29 00:19:33 +01:00
|
|
|
opts="-h -c -v -q -b -i -I -e -w"
|
|
|
|
lopts="--help --createmeta --verbose --quiet --buildreport --interactive
|
2013-08-19 11:30:54 +02:00
|
|
|
--icons --editor --wiki --pretty --clean"
|
2013-10-29 00:19:33 +01:00
|
|
|
case "${prev}" in
|
|
|
|
-e|--editor)
|
|
|
|
_filedir
|
|
|
|
return 0;;
|
|
|
|
esac
|
|
|
|
__complete_options
|
2013-07-14 19:09:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__complete_publish() {
|
2013-12-19 22:55:17 +01:00
|
|
|
opts="-h -v"
|
|
|
|
lopts="--help --verbose"
|
|
|
|
case "${cur}" in
|
|
|
|
-*)
|
|
|
|
__complete_options
|
|
|
|
return 0;;
|
|
|
|
*:)
|
|
|
|
__apk_vercode unsigned
|
|
|
|
return 0;;
|
|
|
|
*)
|
|
|
|
__apk_package unsigned
|
2013-10-29 00:19:33 +01:00
|
|
|
return 0;;
|
|
|
|
esac
|
2013-07-14 19:09:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__complete_checkupdates() {
|
2013-10-29 00:19:33 +01:00
|
|
|
opts="-h -v -p"
|
2013-12-11 19:37:38 +01:00
|
|
|
lopts="--help --verbose --auto --autoonly --commit --gplay"
|
|
|
|
case "${cur}" in
|
|
|
|
-*)
|
|
|
|
__complete_options
|
|
|
|
return 0;;
|
|
|
|
*)
|
2013-10-29 00:19:33 +01:00
|
|
|
__package
|
|
|
|
return 0;;
|
|
|
|
esac
|
2013-07-14 19:09:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__complete_import() {
|
2013-10-29 00:19:33 +01:00
|
|
|
opts="-h -u -s -r"
|
|
|
|
lopts="--help --url --subdir --repo"
|
|
|
|
case "${prev}" in
|
|
|
|
-u|--url|-r|--repo) return 0;;
|
|
|
|
-s|--subdir)
|
|
|
|
_filedir
|
|
|
|
return 0;;
|
|
|
|
esac
|
|
|
|
__complete_options
|
2013-07-14 19:09:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__complete_rewritemeta() {
|
2013-10-29 00:19:33 +01:00
|
|
|
opts="-h -v -p"
|
|
|
|
lopts="--help --verbose --package"
|
|
|
|
case "${prev}" in
|
|
|
|
-p|--package)
|
|
|
|
__package
|
|
|
|
return 0;;
|
|
|
|
esac
|
|
|
|
__complete_options
|
2013-07-14 19:09:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__complete_scanner() {
|
2013-10-29 00:19:33 +01:00
|
|
|
opts="-h -v -p"
|
|
|
|
lopts="--help --verbose --package --nosvn"
|
|
|
|
case "${prev}" in
|
|
|
|
-p|--package)
|
|
|
|
__package
|
|
|
|
return 0;;
|
|
|
|
esac
|
|
|
|
__complete_options
|
2013-07-14 19:09:31 +02:00
|
|
|
}
|
|
|
|
|
2013-08-29 15:26:24 +02:00
|
|
|
__complete_verify() {
|
2013-10-29 00:19:33 +01:00
|
|
|
opts="-h -v -p"
|
|
|
|
lopts="--help --verbose --package"
|
|
|
|
case "${prev}" in
|
|
|
|
-p|--package)
|
|
|
|
__package
|
|
|
|
return 0;;
|
|
|
|
esac
|
|
|
|
__complete_options
|
2013-08-29 15:26:24 +02:00
|
|
|
}
|
|
|
|
|
2013-07-14 19:09:31 +02:00
|
|
|
__complete_stats() {
|
2013-10-29 00:19:33 +01:00
|
|
|
opts="-h -v -d"
|
|
|
|
lopts="--help --verbose --download"
|
|
|
|
__complete_options
|
2013-07-14 19:09:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__complete_server() {
|
2013-10-29 00:19:33 +01:00
|
|
|
opts="-h -v"
|
|
|
|
lopts="--help --verbose update"
|
|
|
|
__complete_options
|
2013-07-14 19:09:31 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 20:28:32 +01:00
|
|
|
__complete_init() {
|
2013-11-05 03:58:42 +01:00
|
|
|
opts="-h -v -d"
|
|
|
|
lopts="--help --verbose --keystore --distinguished-name --repo-keyalias"
|
2013-11-04 20:28:32 +01:00
|
|
|
__complete_options
|
|
|
|
}
|
|
|
|
|
2013-07-14 19:09:31 +02:00
|
|
|
_fdroid() {
|
2013-10-29 00:19:33 +01:00
|
|
|
local cmd cmds aliased
|
|
|
|
cmd=${COMP_WORDS[1]}
|
2013-12-11 18:35:58 +01:00
|
|
|
cmds=" build init install update publish checkupdates import
|
|
|
|
rewritemeta scanner verify stats server "
|
2013-10-29 00:19:33 +01:00
|
|
|
aliased=false
|
2013-07-14 19:09:31 +02:00
|
|
|
|
2013-10-29 00:19:33 +01:00
|
|
|
for c in $cmds; do eval "_fdroid_${c} () {
|
|
|
|
local cur prev cmds opts lopts
|
|
|
|
__fdroid_init ${c};
|
|
|
|
}"; done
|
2013-07-14 19:09:31 +02:00
|
|
|
|
2013-10-29 00:19:33 +01: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
|