if [ "`uname -sr|sed s/\\\\..*//`" == "Darwin 8" ]; then
	if [ "$1" == "" ]; then
		echo "Under MacOS Tiger and earlier you must source setup.sh like this:"
		echo "source /path/to/envi/setup.sh /path/to/envi"
		return
	fi
	home="$1"
else
	home="`dirname ${BASH_SOURCE[0]}`"
fi

export PATH="`$home/bin/envi home`/bin:$PATH"

function envi_complete {
	local cur prev words first_arg second_arg

	COMPREPLY=()

	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"

	#figure out if the first (real) arg has been given
	for (( i = 1 ; i < ${#COMP_WORDS[@]}-1 ; i++ )); do
		word=${COMP_WORDS[$i]}
		if [[ ${word} != -* ]] ; then
			if [ "$first_arg" == "" ]; then
				first_arg=$word
			elif [ "$second_arg" == "" ]; then
				second_arg=$word
			else
				break
			fi
		fi
	done

	#complete first arg
	if [ "$first_arg" == "" ]; then
		completes="`envi playlists` `envi tasks` home tasks playlists env"
	#complete second arg
	#elif [ "$first_arg" != "" ] && [ "$second_arg" == "" ]; then
	#	completes="`envi $first_arg options` env options"
	#cant help complete third arg
	else
		completes=""
	fi

	COMPREPLY=( $(compgen -W "${completes}" -- ${cur}))
	return 0
}
complete -F envi_complete envi

