function remove_from_var
{
    local VAR=$1
    local VAL="$2"
    if test -n "$VAL"; then
        if [[ $ZSH_VERSION ]]; then
            # Zsh
            local OLD_VAL="${(P)VAR}"
        else
            # Bash
            local OLD_VAL="${!VAR}"
        fi
        export $VAR="$(echo "$OLD_VAL" | tr ':' '\n' | grep -v "$VAL" | paste -d: -s)"
    fi
}

function prepend_var
{
    local VAR=$1
    local VAL="$2"
    if test -n "$VAL"; then
        remove_from_var $VAR "$VAL"
        if [[ $ZSH_VERSION ]]; then
            # Zsh
            local OLD_VAL="${(P)VAR}"
        else
            # Bash
            local OLD_VAL="${!VAR}"
        fi
        if test -n "${OLD_VAL}"; then
            export $VAR="$VAL:${OLD_VAL}"
        else
            export $VAR="$VAL"
        fi
    fi
}

function get_script_dir
{
    SCRIPT_NAME="$(readlink -f "${SELF_PATH}")"
    SCRIPT_DIR="$(dirname "${SCRIPT_NAME}")"

    if [ "$SCRIPT_DIR" = '.' ]
    then
       SCRIPT_DIR="$(pwd)"
    fi
    echo "$SCRIPT_DIR"
}

if [ -n "${BASH_SOURCE-}" ]
then
    SELF_PATH="${BASH_SOURCE}"
elif [ -n "${ZSH_VERSION-}" ]
then
    SELF_PATH="${(%):-%x}"
fi

SCRIPT_DIR="$(get_script_dir)"

prepend_var PATH $SCRIPT_DIR/bin
prepend_var PATH $SCRIPT_DIR/cmake/bin
prepend_var PATH $SCRIPT_DIR/python3
prepend_var PATH $SCRIPT_DIR/python3/Scripts
prepend_var PATH $SCRIPT_DIR/make
prepend_var PATH $SCRIPT_DIR/winpty


if [ -n "$PYTHONPATH" ]; then
    unset PYTHONPATH
fi
if [ -n "$PYTHONHOME" ]; then
    unset PYTHONHOME
fi
if [ -z "$PYTHONNOUSERSITE" ]; then
    export PYTHONNOUSERSITE=True
fi

