#  bash completion support
#
#  Copyright (C) 2008 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.

_get_dpkg_cross_list()
{
	grep Choices: /var/lib/dpkg/info/dpkg-cross.templates \
		| cut -d':' -f2 | sed -e 's/None, //' | sed -e 's/,//g'
}

_get_machine_name()
{
	WORK=`cat /etc/emsandbox.conf | grep workingdir | sed -e 's/workingdir: \(.*\)/\1\/machine/'`
	ls $WORK
}

_get_variant_name()
{
	WORK=`cat /etc/emsandbox.conf | grep workingdir | sed -e 's/workingdir: \(.*\)/\1\/machine/'`
	ls -1 $WORK/*
}

_supported_suites()
{
	echo unstable testing stable sid lenny
}

_em_installtdeb()
{
	local cur prev opts arch help quiet cmds
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	arch="-a --arch "
	opts="--no-act --no-sign "
	case "$prev" in
		-@(a|-arch))
		COMPREPLY=( $( _get_dpkg_cross_list $cur ) )
		;;
		*)
		COMPREPLY=( $(compgen -W "${arch}${help}${quiet}${opts}" -- ${cur}) )
		;;
	esac
}
complete -F _em_installtdeb em_installtdeb

_dpkg-gentdeb()
{
	local cur prev opts
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	opts="-p"
	COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
}
complete -F _dpkg-gentdeb dpkg-gentdeb

_dh_gentdeb()
{
	local cur prev opts
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	opts="-p"
	COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
}
complete -F _dh_gentdeb dh_gentdeb

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