mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-20 13:50:12 +01:00
267 lines
5.0 KiB
Bash
267 lines
5.0 KiB
Bash
#!/bin/bash
|
|
#
|
|
# bash-completion - part of the FDroid server tools
|
|
# Commits updates to apps, allowing you to edit the commit messages
|
|
#
|
|
# Copyright (C) 2013 Daniel Martí <mvdan@mvdan.cc>
|
|
#
|
|
# 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/>.
|
|
|
|
# 'fdroid' is completed automatically, but aliases to it are not.
|
|
# For instance, to alias 'fd' to 'fdroid' and have competion available:
|
|
#
|
|
# alias fd='fdroid'
|
|
# complete -F _fdroid fd
|
|
#
|
|
# One can use completion on aliased subcommands as follows:
|
|
#
|
|
# alias fbuild='fdroid build'
|
|
# complete -F _fdroid_build fbuild
|
|
|
|
__fdroid_init() {
|
|
COMPREPLY=()
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
(( $# >= 1 )) && __complete_${1}
|
|
}
|
|
|
|
__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() {
|
|
local p=${cur:0:-1}
|
|
|
|
files=( ${1}/${p}_*.apk )
|
|
[ -f "${files[0]}" ] || return
|
|
|
|
files=( ${files[@]#*_} )
|
|
files=${files[@]%.apk}
|
|
COMPREPLY=( $( compgen -P "${p}:" -W "$files" -- $cur ) )
|
|
}
|
|
|
|
__vercode() {
|
|
local p=${cur:0:-1}
|
|
|
|
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 ) )
|
|
}
|
|
|
|
__complete_options() {
|
|
case "${cur}" in
|
|
--*)
|
|
COMPREPLY=( $( compgen -W "${lopts}" -- $cur ) )
|
|
return 0;;
|
|
*)
|
|
COMPREPLY=( $( compgen -W "${opts} ${lopts}" -- $cur ) )
|
|
return 0;;
|
|
esac
|
|
}
|
|
|
|
__complete_build() {
|
|
opts="-h -v -c -l -s -t -f"
|
|
lopts="--help --verbose --latest --server --resetserver --on-server
|
|
--force --all"
|
|
case "${cur}" in
|
|
-*)
|
|
__complete_options
|
|
return 0;;
|
|
*:)
|
|
__vercode
|
|
return 0;;
|
|
*)
|
|
__package
|
|
return 0;;
|
|
esac
|
|
}
|
|
|
|
__complete_install() {
|
|
opts="-h -v"
|
|
lopts="--help --verbose --all"
|
|
case "${cur}" in
|
|
-*)
|
|
__complete_options
|
|
return 0;;
|
|
*:)
|
|
__apk_vercode repo
|
|
return 0;;
|
|
*)
|
|
__apk_package repo
|
|
return 0;;
|
|
esac
|
|
}
|
|
|
|
__complete_update() {
|
|
opts="-h -c -v -q -b -i -I -e -w"
|
|
lopts="--help --createmeta --verbose --quiet --buildreport --interactive
|
|
--icons --editor --wiki --pretty --clean"
|
|
case "${prev}" in
|
|
-e|--editor)
|
|
_filedir
|
|
return 0;;
|
|
esac
|
|
__complete_options
|
|
}
|
|
|
|
__complete_publish() {
|
|
opts="-h -v"
|
|
lopts="--help --verbose"
|
|
case "${cur}" in
|
|
-*)
|
|
__complete_options
|
|
return 0;;
|
|
*:)
|
|
__apk_vercode unsigned
|
|
return 0;;
|
|
*)
|
|
__apk_package unsigned
|
|
return 0;;
|
|
esac
|
|
}
|
|
|
|
__complete_checkupdates() {
|
|
opts="-h -v"
|
|
lopts="--help --verbose --auto --autoonly --commit --gplay"
|
|
case "${cur}" in
|
|
-*)
|
|
__complete_options
|
|
return 0;;
|
|
*)
|
|
__package
|
|
return 0;;
|
|
esac
|
|
}
|
|
|
|
__complete_import() {
|
|
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
|
|
}
|
|
|
|
__complete_rewritemeta() {
|
|
opts="-h -v"
|
|
lopts="--help --verbose"
|
|
case "${cur}" in
|
|
-*)
|
|
__complete_options
|
|
return 0;;
|
|
*)
|
|
__package
|
|
return 0;;
|
|
esac
|
|
}
|
|
|
|
__complete_scanner() {
|
|
opts="-h -v"
|
|
lopts="--help --verbose --nosvn"
|
|
case "${cur}" in
|
|
-*)
|
|
__complete_options
|
|
return 0;;
|
|
*:)
|
|
__vercode
|
|
return 0;;
|
|
*)
|
|
__package
|
|
return 0;;
|
|
esac
|
|
}
|
|
|
|
__complete_verify() {
|
|
opts="-h -v -p"
|
|
lopts="--help --verbose"
|
|
case "${cur}" in
|
|
-*)
|
|
__complete_options
|
|
return 0;;
|
|
*:)
|
|
__vercode
|
|
return 0;;
|
|
*)
|
|
__package
|
|
return 0;;
|
|
esac
|
|
}
|
|
|
|
__complete_stats() {
|
|
opts="-h -v -d"
|
|
lopts="--help --verbose --download"
|
|
__complete_options
|
|
}
|
|
|
|
__complete_server() {
|
|
opts="-h -v"
|
|
lopts="--help --verbose update"
|
|
__complete_options
|
|
}
|
|
|
|
__complete_init() {
|
|
opts="-h -v -d"
|
|
lopts="--help --verbose --keystore --distinguished-name --repo-keyalias"
|
|
__complete_options
|
|
}
|
|
|
|
_fdroid() {
|
|
local cmd cmds
|
|
cmd=${COMP_WORDS[1]}
|
|
cmds=" build init install update publish checkupdates import
|
|
rewritemeta scanner verify stats server "
|
|
|
|
for c in $cmds; do eval "_fdroid_${c} () {
|
|
local cur prev opts lopts
|
|
__fdroid_init ${c};
|
|
}"; done
|
|
|
|
[[ $cmds == *\ $cmd\ * ]] && _fdroid_${cmd} || {
|
|
(($COMP_CWORD == 1)) && COMPREPLY=( $( compgen -W "${cmds}" -- $cmd ) )
|
|
}
|
|
}
|
|
|
|
_fd-commit() {
|
|
__package
|
|
}
|
|
|
|
complete -F _fdroid fdroid
|
|
complete -F _fd-commit fd-commit
|
|
|
|
return 0
|