#
# Splunk -- It's tasty.
#

# NOTE!!! starting in Splunk 3.2, this is just a convenience script useful for
# setting the environment variables splunk uses into your local shell.  You
# can no longer change SPLUNK_HOME or SPLUNK_DB settings here -- see
# ../etc/splunk-launch.conf instead

# We need to find the "splunk" binary which is in the same directory as this
# script.  Unfortunately there's no portable way of finding what path we're
# being sourced from.  However, bash puts our exact command in $BASH_SOURCE
# and zsh puts it in $0, so check for those here.  If you're running a
# different shell we'll have to assume that $SPLUNK_HOME is already set
# properly
case "X$BASH_SOURCE" in
X)
	case "X$0" in
	X*setSplunkEnv)
		_sourced_dirname=`dirname "$0"`
		eval `"${_sourced_dirname}/splunk" envvars | grep -v Warning`
		unset _sourced_dirname
		;;
	*)
		case "X$SPLUNK_HOME" in
		X)
			echo >&2 'ERROR: please set $SPLUNK_HOME first'
			;;
		*)
			eval `"$SPLUNK_HOME/bin/splunk" envvars | grep -v Warning`
			;;
		esac
		;;
	esac
	;;
*)
	_sourced_dirname=`dirname "$BASH_SOURCE"`
	eval `"${_sourced_dirname}/splunk" envvars | grep -v Warning`
	unset _sourced_dirname
	;;
esac

# instead of checking $SHELL = bash, we have to check for BASH_VERSION
# $SHELL variable can be passed on - executing setSplunkEnv inside a bash
# shell with `sh setSplunkEnv` would still cause $SHELL to be "bash"
if [ -n "$BASH_VERSION" ] && [ "x$SPLUNK_HOME" != "x" ]; then
    . "$SPLUNK_HOME/share/splunk/cli-command-completion.sh" >/dev/null 2>/dev/null
fi

if [ $? -eq 0 ]; then
    echo 'Tab-completion of "splunk <verb> <object>" is available.' >&2
fi
