# bash completion for cpan2dist
# $Id: /local/home/dev/bash-completion/minicom 190 2009-11-26T22:23:28.122461Z guillaume  $

_cpan2dist()
{
	local cur prev

	COMPREPLY=()
	cur=${COMP_WORDS[COMP_CWORD]}
	prev=${COMP_WORDS[COMP_CWORD-1]}

	case $prev in
		--format)
			COMPREPLY=( $( compgen -W '$(perl -MCPANPLUS::Dist -e "print map { \"\$_\n\" } CPANPLUS::Dist->dist_types")' -- $cur ) )
			return 0
			;;
		--@(banlist|ignorelist|modulelist|logfile))
			_filedir
			return 0
			;;
	esac

	if [[ "$cur" == -* ]]; then
		COMPREPLY=( $( compgen -W '--help --skiptest --force \
			--verbose --keepsource --makefile --buildprereq \
			--archive --flushcache --defaults --edit-metafile \
			--format --ban --banlist --ignore --ignorelist \
			--modulelist --logfile --timeout --set-config \
			--set-program --dist-opts --default-banlist \
			--default-ignorelist' -- $cur ) )
	else
		COMPREPLY=( $( zgrep "^${cur//-/::}" \
			$HOME/.cpanplus/02packages.details.txt.gz 2>/dev/null \
			| awk '{print $1}' | sed -e 's/::/-/g' ) ) 
	fi
}
complete -F _cpan2dist cpan2dist
