# bash completion for rpmbuildupdate
# $Id: rpmbuildupdate.in 223771 2007-06-13 20:42:01Z guillomovitch $

_rpmbuildupdate()
{
	local cur prev rpmpath file

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

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


	if [[ "$cur" == -* ]]; then
		COMPREPLY=( $( compgen -W '--srpms --rpmoption --release \
			--releasesuffix --changelog --top --nodownload \
			--noupdate --noupdate-revision --noupdate-changelog \
			--nobuild --nobuild-binaries --nobuild-source \
			--execute --execafterbuild --installbuildrequires' \
			-- $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
