# version _BASH_SCRIPT_COMPILER_VERSION_
__BASH_SCRIPT_COMPILER_SCRIPT_NAME_-completion() 
{
	local cur prev opts tag help
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	prevPrev="${COMP_WORDS[COMP_CWORD-2]}"
	opts="compile deploy new help config"
	config="print set init"

	# TODO check if this is still the most efficient way to list help options
	HELP_PATH=${BASH_SOURCE%/*}/_BASH_SCRIPT_COMPILER_SCRIPT_NAME_-help
	help=${opts}
	#help=`ls $HELP_PATH`

	if [[ ${cur} == "help" ]] ; then
		createFromString "${help}"
		return 0
	elif [[ $COMP_CWORD -gt 1 ]]; then
		if [ "$prev" == "config" ]; then
			createFromString "$config"
		elif [ "$prevPrev" == "config" ]; then
			# no suggestions after config xyz
			return 0
		elif [ "$prev" == "compile" ] || [ "$prev" == "-c" ]; then
			createFromDirectory "."
		elif [ "$prev" == "deploy" ] || [ "$prev" == "-d" ]; then
			createFromDirectory "."
		else
			createFromString "${opts}"
		fi
		return 0
	elif [[ $COMP_CWORD -eq 1 ]]; then
		createFromString "${opts}"
		return 0
	fi
}

createFromString() {
	COMPREPLY=( $(compgen -W "${1}" -- ${cur}) )
}

createFromDirectory() {
	pushd $1 >/dev/null
	COMPREPLY=( $(compgen -o plusdirs -- $cur) )
	popd >/dev/null
}

complete -F __BASH_SCRIPT_COMPILER_SCRIPT_NAME_-completion _BASH_SCRIPT_COMPILER_SCRIPT_NAME_
