#have bashdepends &&
feature='"bashdepends <verb> <object>" tab-completion'
[ `basename $SHELL` != 'bash' ]     && echo "Sorry, $feature is only for bash" >&2                                     && return 11
[ ${BASH_VERSINFO[0]} -lt 4 ]       && echo "Sorry, $feature only works with bash 4.0 or higher" >&2                        && return 12
[ $(type -t complete) != 'builtin' ] && echo "Sorry, $feature requires a bash that supports programmable command completion" >&2 && return 13

_bashdepends()
{
	dashify()
	{
		local i

		for (( i=0; i < "${#COMPREPLY[@]}"; i++ )); do
			if [ "${#COMPREPLY[i]}" -le 2 ]; then
				COMPREPLY[i]=-"${COMPREPLY[i]}"
			else
				COMPREPLY[i]=--"${COMPREPLY[i]}"
			fi
		done
	}

	local cur cur_nodash # prev

	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	cur_nodash="${cur#-}"
	# prev="${COMP_WORDS[COMP_CWORD-1][COMP_CWORD-2]}"

	if [ "${COMP_CWORD}" = 1 ]; then
		# first parameter on line
		case "${cur}" in
		-d*)
			COMPREPLY=( "$( compgen -W 'depends' \
				       ${cur}_nodash" ) )
			dashify
			return 0
			;;
		-h*)
			COMPREPLY=( "$( compgen -W 'help' \
				       "${cur}_nodash" )" )
			dashify
			return 0
			;;
		-v*)
			COMPREPLY=( "$( compgen -W 'version' \
				       "${cur}_nodash" )" )
			dashify
			return 0
			;;
		-*)
			COMPREPLY=( "$( compgen -W 'depends version help' ${cur_nodash#-} )" )
			dashify;
			return 0
			;;
		--*)
			COMPREPLY=( "$( compgen -W 'depends version help' ${cur_nodash#-} )" )
			dashify;
			return 0
			;;
		*)
			COMPREPLY=( "$( compgen -W 'd h v' \
				       "${cur}_nodash" )" )
			dashify
			return 0
			;;
			;;
		esac
	fi

	if [ "${COMP_CWORD}" = 2 ]; then
		case "${COMP_WORDS[1]}" in
		--d*)
			# standard filename completion
			COMPREPLY=( "$( compgen -f ${cur} )" )
			return 0
			;;
		-d)
			# standard filename completion
			COMPREPLY=( "$( compgen -f ${cur} )" )
			return 0
			;;
		--h*)
			# complete on list of relevant options
			COMPREPLY=( "$( compgen -W 'depends version' "${cur_nodash#-}" )" )
			#dashify;
			return 0
			;;
		-h)
			# complete on list of relevant options
			COMPREPLY=( "$( compgen -W 'depends version' "${cur_nodash#-}" )" )
			#dashify;
			return 0
			;;
		esac
	fi
}
complete -F _bashdepends bashdepends
