abf-console-client-src/bash_autocomplete
2012-10-25 15:26:22 +04:00

143 lines
2.7 KiB
Bash

# bash-completion add-on for rpmlint
# http://bash-completion.alioth.debian.org/
__abf_opts()
{
if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${@}" -- "${cur}") )
return 0
fi
}
__abf_get()
{
__abf_opts "--branch"
}
__abf_put()
{
__abf_opts ""
}
__abf_show()
{
__abf_opts "--project"
shows="build-repos build-platforms save-to-repos save-to-platforms"
if [[ ${cur} != -* ]] ; then
if [[ ${prev} == -* ]] ; then
return 0;
fi
COMPREPLY=( $(compgen -W "${shows}" -- "${cur}") )
return 0
fi
}
__abf_locate()
{
__abf_opts "--project --directory"
actions="update update-recursive"
if [[ ${cur} != -* ]] ; then
if [[ ${prev} == -* ]] ; then
return 0;
fi
COMPREPLY=( $(compgen -W "${actions}" -- "${cur}") )
return 0
fi
}
__abf_build()
{
__abf_opts "--branch --tag --commit --target-platform --arch --repository --save-to-repository --auto-publish --update-type --skip-spec-check"
update_types="security bugfix enhancement recommended newpackage"
if [ ${prev} == -r ] || [ ${prev} == --repository ] ; then
COMPREPLY=( $(compgen -W "`abf-local show build-repos`" -- "${cur}") )
return 0
fi
if [ ${prev} == -s ] || [ ${prev} == --save-to-repository ] ; then
proj=""
next=0
for i in ${COMP_WORDS[@]}
do
if [[ $next == 1 ]] ; then
proj=$i;
next=0;
fi
if [[ "$i" == "-p" || "$i" == "--project" ]] ; then
next=1;
fi;
done
if [ -n "${proj}" ] ; then
COMPREPLY=( $(compgen -W "`abf-local show save-to-repos -p ${proj}`" -- "${cur}") )
fi
return 0
fi
if [ ${prev} == --update-type ] ; then
COMPREPLY=( $(compgen -W "${update_types}" -- "${cur}") )
return 0
fi
}
__abf_publish()
{
__abf_opts "--pack"
}
__abf_backport()
{
__abf_opts "--pack"
if [[ ${cur} != -* ]] ; then
branches=`git branch --no-color | sed 's/^..//' | xargs echo`
COMPREPLY=( $(compgen -W "${branches}" -- "${cur}") )
return 0
fi
}
__abf_buildstatus()
{
__abf_opts ""
}
__abf_help()
{
__abf_opts ""
}
__abf()
{
local opts modes
modes="help get put show build publish backport buildstatus locate"
COMPREPLY=()
mode="${COMP_WORDS[1]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cur="${COMP_WORDS[COMP_CWORD]}"
if [ "$COMP_CWORD" == "1" ] || ( [ "$COMP_CWORD" == "2" ] && [ "$mode" == "help" ] ); then
COMPREPLY=( $(compgen -W "${modes}" -- ${cur}) )
return 0
fi
for i in ${modes}
do
if [[ $i == $mode ]] ; then
eval __abf_${i};
fi
done
}
complete -F __abf abf