#  bash completion support
#
#  Copyright (C) 2008,2009 Neil Williams <codehelp@debian.org>
#
#  This package is free software; you can redistribute it and/or modify
#  it under the terms of the GNU 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 General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Remember to always put a space at the end of a line of options.

_emautogrip()
{
	local cur prev opts arch help default cmds
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	help="-h -? --help --version --missing "
	cmds="-p --package -s --source -n --dry-run --edos --build-depends "
	opts="-b --base-path -m --mirror -t --testing --noskipold --add-new "
	default="--filter-name --grip-name "
	arch=" "
	case "$prev" in
		-@(p|-package))
		COMPREPLY=( $( apt-cache pkgnames $cur ) )
		;;
		-@(s|-source))
		COMPREPLY=( $( apt-cache pkgnames $cur ) )
		;;
		*)
		COMPREPLY=( $(
			compgen -W "${arch}${quiet}${cmds}${opts}${help}${default}" -- ${cur}) )
		;;
	esac
}
complete -o default -F _emautogrip em_autogrip

_emgrip()
{
	local cur prev opts arch help quiet cmds
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	help="-h -? --help --version "
	quiet="--verbose --quiet -v -q "
	cmds="-o --outdir --vendor "
	COMPREPLY=( $(
		compgen -G "${cur}*.changes"
		compgen -G "${cur}*.deb"
		compgen -G "${cur}*.dsc"
		compgen -W "${arch}${quiet}${cmds}${help}" -- ${cur}) )
}
complete -o default -F _emgrip emgrip

_apt_grip()
{
	local cur prev opts arch help quiet cmds arch
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	help="-h -? --help --version "
	quiet="--verbose --quiet -v -q "
	opts=" -M --mirror -V --vendor -S --suite -b --build "
	cmds=" -k --keep-cache -c --clean-cache "
	arch=" --ignore-status -a --arch "
	COMPREPLY=( $(
		compgen -W "${opts}${quiet}${cmds}${arch}${help}" -- ${cur}) )
}
complete -o default -F _apt_grip apt-grip

_emgrip_build()
{
	local cur prev opts cmds
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_WORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	help="-h -? --help "
	opts=" -n --dry-run --debuild "
	COMPREPLY=( $(
		compgen -W "${opts}${quiet}${cmds}${help}" -- ${cur}) )
}
complete -o default _emgrip_build emgrip-build

