#!/bin/sh
_CONDA_ROOT="/opt/anaconda1anaconda2anaconda3"
#!/bin/sh

_conda_set_vars() {
    # set _CONDA_SHELL_FLAVOR
    if [ -n "${BASH_VERSION:+x}" ]; then
        _CONDA_SHELL_FLAVOR=bash
    elif [ -n "${ZSH_VERSION:+x}" ]; then
        _CONDA_SHELL_FLAVOR=zsh
    elif [ -n "${KSH_VERSION:+x}" ]; then
        _CONDA_SHELL_FLAVOR=ksh
    elif [ -n "${POSH_VERSION:+x}" ]; then
        _CONDA_SHELL_FLAVOR=posh
    else
        # https://unix.stackexchange.com/a/120138/92065
        local _q="$(ps -p$$ -o cmd="",comm="",fname="" 2>/dev/null | sed 's/^-//' | grep -oE '\w+' | head -n1)"
        if [ "$_q" = dash ]; then
            _CONDA_SHELL_FLAVOR=dash
        else
            (>&2 echo "Unrecognized shell.")
            return 1
        fi
    fi

    # https://unix.stackexchange.com/questions/4650/determining-path-to-sourced-shell-script/
    local script_dir
    case "$_CONDA_SHELL_FLAVOR" in
        bash) script_dir="$(dirname "${BASH_SOURCE[0]}")";;
        zsh) script_dir="$(dirname "${(%):-%x}")";;  # http://stackoverflow.com/a/28336473/2127762
        dash) x=$(lsof -p $$ -Fn0 | tail -1); script_dir="$(dirname "${x#n}")";;
        *) script_dir="$(cd "$(dirname "$_")" && echo "$PWD")";;
    esac

    if [ -z "${_CONDA_ROOT+x}" ]; then
        _CONDA_ROOT="$(dirname "$script_dir")"
    fi

}

_conda_script_is_sourced() {
    # http://stackoverflow.com/a/28776166/2127762
    local sourced=0
    if [ -n "${ZSH_EVAL_CONTEXT:+x}" ]; then
      case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac
    elif [ -n "${KSH_VERSION:+x}" ]; then
      [ "$(cd $(dirname -- $0) && pwd -P)/$(basename -- $0)" != "$(cd $(dirname -- ${.sh.file}) && pwd -P)/$(basename -- ${.sh.file})" ] && sourced=1
    elif [ -n "${BASH_VERSION:+x}" ]; then
      [ "${BASH_SOURCE[0]}" = "$0" ] && sourced=1
    else # All other shells: examine $0 for known shell binary filenames
      # Detects `sh` and `dash`; add additional shell filenames as needed.
      case ${0##*/} in sh|dash) sourced=0;; *) sourced=1;; esac
    fi
    return $sourced
}

if ! _conda_script_is_sourced; then
    (
      >&2 echo "Error: deactivate must be sourced. Run 'source deactivate'"
      >&2 echo "instead of 'deactivate'."
    )
    exit 1
fi

_conda_set_vars
. "$_CONDA_ROOT/etc/profile.d/conda.sh" || return $?
_conda_deactivate
