# bash completion for rpmbuildupdate
# $Id: rpmbuildupdate.comp.in 43173 2006-08-03 09:24:35Z guillomovitch $

_rpmbuildupdate()
{
	local cur prev rpmpath file

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

	case $prev in
		--rpmmon)
			_filedir
			return 0
			;;
		--@(srpms|top))
			_filedir -d
			return 0
			;;
	esac


	if [[ "$cur" == -* ]]; then
		COMPREPLY=( $( compgen -W '--rpmmon --srpms --rpmoption \
			--release --changelog --deps --log --nosource \
			--noupdate --top --nobuild --execute -c --execafterbuild' -- $cur ) )
	else
		# get source rpm path
		for file in /etc/rpmbuildupdate.conf $HOME/.rpmbuildupdaterc; do
			if [ -f $file ]; then
				rpmpath=`awk -F" *= *" '/srpms/ {print $2}' $file`
			fi
		done
		for (( i=1; i < COMP_CWORD; i++ )); do
			if [[ "${COMP_WORDS[i]}" == --srpms ]]; then
				rpmpath=${COMP_WORDS[i+1]}
				break
			fi
		done
		if [ -n "$rpmpath" ]; then
			rpmpath=${rpmpath//,/ }
			COMPREPLY=( $( eval command ls "$rpmpath" 2>/dev/null | \
				sed -ne 's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+\.src\.rpm$|\1|p' ) )
		fi
		_filedir
	fi
}
complete -F _rpmbuildupdate $filenames rpmbuildupdate
