flatpak-builder/completion/xdg-app

313 lines
13 KiB
Plaintext
Raw Normal View History

2015-01-23 05:52:20 +00:00
[ -z "$BASH_VERSION" ] && return
__contains_word () {
local w word=$1; shift
for w in "$@"; do
[[ $w = "$word" ]] && return
done
}
_xdg-app() {
local cur prev
2015-01-23 05:52:20 +00:00
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
if [[ $cur == "=" ]] && [[ "$prev" = -* ]]; then
cur=""
elif [[ $prev == "=" ]] && [[ "${COMP_WORDS[COMP_CWORD-2]}" = -* ]]; then
prev=${COMP_WORDS[COMP_CWORD-2]}
fi
2015-01-23 05:52:20 +00:00
local i verb comps mode
local remote name
local dir cmd sdk loc
local -A VERBS=(
[ALL]='add-remote modify-remote delete-remote ls-remote list-remotes install-runtime update-runtime uninstall-runtime list-runtimes install-app update-app uninstall-app list-apps run override export-file build-init build build-finish build-export repo-update make-app-current'
[MODE]='add-remote modify-remote delete-remote ls-remote list-remotes install-runtime update-runtime uninstall-runtime list-runtimes install-app update-app uninstall-app list-apps make-app-current'
[PERMS]='run override build build-finish'
[UNINSTALL]='uninstall-runtime uninstall-app'
2015-03-10 15:33:56 +00:00
[ARCH]='build-init install-runtime install-app run uninstall-runtime uninstall-app update-runtime update-app make-app-current'
2015-01-23 05:52:20 +00:00
)
local -A OPTS=(
[GENERAL]='--help --verbose --version'
[MODE]='--user --system'
[ARCH]='--arch='
[PERMS]='--share= --unshare= --socket= --nosocket= --device= --nodevice= --filesystem= --env= --own-name= --talk-name= --persist='
[ADD_REMOTE]='--no-gpg-verify --if-not-exists --title= --gpg-import= --gpg-key='
[MODIFY_REMOTE]='--no-gpg-verify --gpg-verify --title= --gpg-import= --gpg-key='
[LIST_REMOTES]='--show-details'
[LS_REMOTE]='--show-details --runtimes --apps --updates'
[UNINSTALL]='--keep-ref --force-remove'
[RUN]='--command= --branch= --devel --runtime='
[BUILD_INIT]='--arch= --var='
[BUILD]='--runtime'
[BUILD_FINISH]='--command= --allow'
[BUILD_EXPORT]='--subject= --body='
[EXPORT_FILE]='--app= --allow-write --allow-delete --allow-grant-permission --unique'
[ARG]='--arch --command --branch --var --share --unshare --socket --nosocket --device --nodevice --subject --body --title --runtime --filesystem'
2015-01-23 05:52:20 +00:00
)
if __contains_word "--user" ${COMP_WORDS[*]}; then
mode=--user
else
mode=--system
2015-01-23 05:52:20 +00:00
fi
if __contains_word "$prev" ${OPTS[ARG]}; then
case $prev in
--arch)
comps='x86_64 i686'
;;
--command)
comps=$(compgen -A command)
;;
2015-02-06 16:06:42 +00:00
--var|--runtime)
comps=$(xdg-app $mode list-runtimes)
2015-01-23 05:52:20 +00:00
;;
--share|--noshare)
comps='network ipc'
;;
--device|--nodevice)
comps='dri'
;;
--socket|--nosocket)
comps='x11 wayland pulseaudio system-bus session-bus'
2015-01-23 05:52:20 +00:00
;;
--branch|--subject|--body|--title)
2015-01-23 05:52:20 +00:00
comps=''
;;
--filesystem)
comps='host home xdg-desktop xdg-documents xdg-download xdg-music xdg-pictures xdg-public-share xdg-templates xdg-videos'
;;
2015-01-23 05:52:20 +00:00
esac
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
fi
for ((i=0; i < COMP_CWORD; i++)); do
if [[ "${COMP_WORDS[i]}" = -* ]]; then
continue
fi
if __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
continue
fi
if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
test -z $verb; then
verb=${COMP_WORDS[i]}
elif [[ $verb = install-* ]]; then
if [[ -z $remote ]]; then
remote=${COMP_WORDS[i]}
elif [[ -z $name ]]; then
name=${COMP_WORDS[i]}
fi
elif [[ $verb =~ (update-*|uninstall-*|run) ]]; then
if [[ -z $name ]]; then
name=${COMP_WORDS[i]}
fi
elif [[ $verb = build-init ]]; then
if [[ -z $dir ]]; then
dir=${COMP_WORDS[i]}
elif [[ -z $sdk ]]; then
sdk=${COMP_WORDS[i]}
elif [[ -z $name ]]; then
name=${COMP_WORDS[i]}
fi
elif [[ $verb = build ]]; then
if [[ -z $dir ]]; then
dir=${COMP_WORDS[i]}
elif [[ -z $cmd ]]; then
cmd=${COMP_WORDS[i]}
fi
elif [[ $verb = build-finish ]]; then
if [[ -z $dir ]]; then
dir=${COMP_WORDS[i]}
fi
elif [[ $verb = build-export ]]; then
if [[ -z $loc ]]; then
loc=${COMP_WORDS[i]}
elif [[ -z $dir ]]; then
dir=${COMP_WORDS[i]}
elif [[ -z $name ]]; then
name=${COMP_WORDS[i]}
fi
2015-01-25 03:01:57 +00:00
elif [[ $verb = repo-update ]]; then
if [[ -z $loc ]]; then
loc=${COMP_WORDS[i]}
fi
elif [[ $verb = export-file ]]; then
if [[ -z $file ]]; then
file=${COMP_WORDS[i]}
fi
2015-01-23 05:52:20 +00:00
fi
done
if [[ -z $verb ]]; then
comps="${VERBS[*]}"
elif [[ "$cur" = -* ]]; then
comps="${OPTS[GENERAL]}"
if __contains_word "$verb" ${VERBS[MODE]}; then
comps="$comps ${OPTS[MODE]}"
fi
if __contains_word "$verb" ${VERBS[PERMS]}; then
comps="$comps ${OPTS[PERMS]}"
fi
2015-01-23 05:52:20 +00:00
if [ "$verb" = "list-remotes" ]; then
comps="$comps ${OPTS[LIST_REMOTES]}"
fi
if __contains_word "$verb" ${VERBS[ARCH]}; then
comps="$comps ${OPTS[ARCH]}"
fi
if __contains_word "$verb" ${VERBS[UNINSTALL]}; then
comps="$comps ${OPTS[UNINSTALL]}"
fi
2015-01-23 05:52:20 +00:00
if [ "$verb" = "run" ]; then
comps="$comps ${OPTS[RUN]}"
fi
if [ "$verb" = "export-file" ]; then
comps="$comps ${OPTS[EXPORT_FILE]}"
fi
if [ "$verb" = "ls-remote" ]; then
comps="$comps ${OPTS[LS_REMOTE]}"
2015-01-23 05:52:20 +00:00
fi
if [ "$verb" = "build-init" ]; then
comps="$comps ${OPTS[BUILD_INIT]}"
fi
if [ "$verb" = "build" ]; then
comps="$comps ${OPTS[BUILD]}"
fi
if [ "$verb" = "build-finish" ]; then
comps="$comps ${OPTS[BUILD_FINISH]}"
fi
if [ "$verb" = "build-export" ]; then
comps="$comps ${OPTS[BUILD_EXPORT]}"
fi
if [ "$verb" = "repo-update" ]; then
comps="$comps ${OPTS[REPO_UPDATE]}"
fi
if [ "$verb" = "add-remote" ]; then
comps="$comps ${OPTS[ADD_REMOTE]}"
fi
if [ "$verb" = "modify-remote" ]; then
comps="$comps ${OPTS[MODIFY_REMOTE]}"
fi
2015-01-23 05:52:20 +00:00
else
case "$verb" in
add-remote|modify-remote|delete-remote|ls-remote)
comps=$(xdg-app $mode list-remotes)
2015-01-23 05:52:20 +00:00
;;
install-runtime)
if [[ -z $remote ]]; then
comps=$(xdg-app $mode list-remotes)
2015-01-23 05:52:20 +00:00
elif [[ -z $name ]]; then
comps=$(xdg-app $mode repo-contents $remote --runtimes)
2015-01-23 05:52:20 +00:00
else
comps='' # FIXME: branches
fi
;;
list-remotes|list-runtimes|list-apps)
comps=''
;;
update-runtime|uninstall-runtime)
if [[ -z $name ]]; then
comps=$(xdg-app $mode list-runtimes)
2015-01-23 05:52:20 +00:00
else
comps='' # FIXME: branches
fi
;;
install-app)
if [[ -z $remote ]]; then
comps=$(xdg-app $mode list-remotes)
2015-01-23 05:52:20 +00:00
elif [[ -z $name ]]; then
comps=$(xdg-app $mode repo-contents $remote --apps)
2015-01-23 05:52:20 +00:00
else
comps='' # FIXME: branches
fi
;;
update-app|uninstall-app)
if [[ -z $name ]]; then
comps=$(xdg-app $mode list-apps)
2015-01-23 05:52:20 +00:00
else
comps='' # FIXME: branches
fi
;;
run|override)
2015-01-23 05:52:20 +00:00
if [[ -z $name ]]; then
comps=$(xdg-app $mode list-apps)
2015-01-23 05:52:20 +00:00
fi
;;
2015-01-23 05:52:20 +00:00
build-init)
if [[ -z $dir ]]; then
comps=''
compopt -o dirnames
elif [[ -z $sdk ]]; then
comps="$(xdg-app list-runtimes) $(xdg-app --user list-runtimes)"
2015-01-23 05:52:20 +00:00
elif [[ -z $name ]]; then
comps="$(xdg-app list-runtimes) $(xdg-app --user list-runtimes)"
2015-01-23 05:52:20 +00:00
else
comps='' # FIXME: branches
fi
;;
build)
if [[ -z $dir ]]; then
comps=''
compopt -o dirnames
elif [[ -z $cmd ]]; then
comps=''
compopt -o bashdefault
fi
;;
build-finish)
if [[ -z $dir ]]; then
comps=''
compopt -o dirnames
fi
;;
build-export)
if [[ -z $loc ]]; then
comps=''
compopt -o dirnames
elif [[ -z $dir ]]; then
comps=''
compopt -o dirnames
fi
;;
2015-01-25 03:01:57 +00:00
repo-update)
if [[ -z $loc ]]; then
comps=''
compopt -o dirnames
fi
;;
export-file)
if [[ -z $file ]]; then
comps=''
compopt -o dirnames
fi
;;
2015-01-23 05:52:20 +00:00
esac
fi
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
[[ $COMPREPLY == *= ]] && compopt -o nospace
2015-01-23 05:52:20 +00:00
return 0
}
complete -F _xdg-app xdg-app