#have repostorm &&
feature='"repostorm <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

_repostorm()
{
    local cur cur_nodash prev

    COMPREPLY=()
    cur=$(_get_cword)
    prev=${COMP_WORDS[COMP_CWORD-1]}
	cur_nodash="${cur#-}"
	# prev="${COMP_WORDS[COMP_CWORD-1][COMP_CWORD-2]}"
    # local cur cur_nodash # prev
	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
	}

	if [ "$COMP_CWORD" = 1 ]; then
		# first parameter on line
		case "$cur" in
		-b*)
			COMPREPLY=( $( compgen -W 'build' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-a*)
			COMPREPLY=( $( compgen -W 'analyze' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-C*)
			COMPREPLY=( $( compgen -W 'cleanfolder' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-e*)
			COMPREPLY=( $( compgen -W 'extract' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-d*)
			COMPREPLY=( $( compgen -W 'dummy' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-f*)
			COMPREPLY=( $( compgen -W 'fix' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-l*)
			COMPREPLY=( $( compgen -W 'log' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-h*)
			COMPREPLY=( $( compgen -W 'help' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-p*)
			COMPREPLY=( $( compgen -W 'prepare' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-R*)
			COMPREPLY=( $( compgen -W 'relax' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-P*)
			COMPREPLY=( $( compgen -W 'publish' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-s*)
			COMPREPLY=( $( compgen -W 'scan' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-S*)
			COMPREPLY=( $( compgen -W 'service' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-V*)
			COMPREPLY=( $( compgen -W 'verbose' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-r*)
			COMPREPLY=( $( compgen -W 'report' "$cur_nodash" ) )
			dashify
			return 0
			;;
		-v*)
			COMPREPLY=( $( compgen -W 'version' "$cur_nodash" ) )
			dashify
			return 0
			;;
		--*)
			COMPREPLY=( $( compgen -W 'analyze build extract cleanfolder dummy fix help log prepare publish relax report scan service verbose version' "${cur_nodash#-}" ) )
			dashify
			return 0
			;;
		*)
			COMPREPLY=( $( compgen -W 'analyze build extract cleanfolder dummy fix help log prepare publish relax report scan service verbose version' "${cur_nodash#-}" ) )
			dashify
			return 0
			;;
		esac
	fi
	if [ "$COMP_CWORD" = 2 ]; then
		case "${COMP_WORDS[1]}" in
		--a*)
			# analyze completion
			COMPREPLY=( $( compgen -G "$cur\*.deb" ) )
			return 0
			;;
		-a)
			# analyze completion
			COMPREPLY=( $( compgen -G "$cur\*.deb" ) )
			return 0
			;;

		--b*)
			# standard directory name completion
			COMPREPLY=( $( compgen -d "$cur" ) )
			return 0
			;;
		-b)
			# standard directory name completion
			COMPREPLY=( $( compgen -d "$cur" ) )
			return 0
			;;
		--clear*)
			# filename completion only showing error logs
			COMPREPLY=( $( compgen -G "$cur\*.errors" ) )
			return 0
			;;
		-c)
			# filename completion only showing error logs
			COMPREPLY=( $( compgen -G "$cur\*.errors" ) )
			return 0
			;;
		--clean*)
			# standard directory name completion
			COMPREPLY=( $( compgen -d "$cur" ) )
			return 0
			;;
		-C)
			# standard directory name completion
			COMPREPLY=( $( compgen -d "$cur" ) )
			return 0
			;;
		--e*)
			# filename completion only showing debs
			COMPREPLY=( $( compgen -f "$cur" ) )
			# complete on deb files
			COMPREPLY=( $( compgen -G "$cur\*.deb" ) )
			return 0
			;;
		-e)
			# filename completion only showing debs
			COMPREPLY=( $( compgen -f "$cur" ) )
			# complete on deb files
			COMPREPLY=( $( compgen -G "$cur\*.deb" ) )
			return 0
			;;
		--f*)
			# filename completion only showing error logs
			COMPREPLY=( $( compgen -G "$cur\*.errors" ) )
			return 0
			;;
		-f*)
			# filename completion only showing error logs
			COMPREPLY=( $( compgen -G "$cur\*.errors" ) )
			return 0
			;;
		--l*)
			COMPREPLY=( $( compgen -W 'view clear' \
				      "$cur_nodash" ) )
			dashify
			return 0
			;;
		-l*)
			COMPREPLY=( $( compgen -W 'view clear' \
				      "$cur_nodash" ) )
			dashify
			return 0
			;;
		--h*)
			# complete on list of relevant options
			COMPREPLY=( $( compgen -W 'analyze build clearlogs cleanfolder extract fix help prepare publish relax report service scan verbose version' "${cur_nodash#-}" ) )
			#dashify;
			return 0
			;;
		-h)
			# complete on list of relevant options
			COMPREPLY=( $( compgen -W 'analyze build clearlogs cleanfolder extract fix help prepare publish relax report service scan verbose version' "${cur_nodash#-}" ) )
			#dashify;
			return 0
			;;
		--p*)
			# prepare / publish long
			COMPREPLY=( $( compgen -d "$cur" ) )
			return 0
			;;
		-p)
			# prepare short
			COMPREPLY=( $( compgen -d "$cur" ) )
			return 0
			;;
		-P)
			# publish short
			COMPREPLY=( $( compgen -d "$cur" ) )
			return 0
			;;
		--rel*)
			# relax long
			COMPREPLY=( $( compgen -d "$cur" ) )
			return 0
			;;
		--rep*)
			# report long
			COMPREPLY=( $( compgen -G "$cur\*.deb" ) )
			return 0
			;;
		-R)
			# relax short
			COMPREPLY=( $( compgen -d "$cur" ) )
			return 0
			;;
		-r)
			# report short
			COMPREPLY=( $( compgen -G "$cur\*.deb" ) )
			return 0
			;;
		--se*)
			# service long
			COMPREPLY=( $( compgen -W 'on off' "${cur_nodash#-}" ) )
			#dashify;
			return 0
			;;
		-S)
			# service short
			COMPREPLY=( $( compgen -W 'on off' "${cur_nodash#-}" ) )
			#dashify;
			return 0
			;;
		--sc*)
			# scan long
			COMPREPLY=( $( compgen -G "$cur\*.errors" ) )
			return 0
			;;
		-s)
			# scan short
			COMPREPLY=( $( compgen -d "$cur" ) )
			return 0
			;;
		esac
	fi
	case "${COMP_WORDS[2]}" in
	build)
		# standard filename completion
		COMPREPLY=( $( compgen -W '--defaultde=' "${cur_nodash#-}" ) )
		return 0
		;;
	esac
}
complete -F _repostorm repostorm
