diff --git a/bin/pyenv-sh-activate b/bin/pyenv-sh-activate index 323c1b1..3c416ba 100755 --- a/bin/pyenv-sh-activate +++ b/bin/pyenv-sh-activate @@ -69,6 +69,29 @@ if ! pyenv-virtualenv-prefix "${versions}" 1>/dev/null 2>&1; then fi shell="${PYENV_SHELL:-${SHELL##*/}}" +prefix="$(pyenv-prefix "${versions}")" + +unset conda_env + +if [ -f "${prefix}/bin/conda" ]; then + if [[ "${prefix}" != "${prefix%/envs/*}" ]]; then + case "$shell" in + bash ) + conda_env="${prefix##*/envs/}" + ;; + zsh ) + conda_env="${prefix##*/envs/}" + ;; + * ) + echo "false" + exit 1 + ;; + esac + else + echo "false" + exit 1 + fi +fi # Display setup instruction, if pyenv-virtualenv has not been initialized. # if 'pyenv virtualenv-init -' is not found in "$profile" @@ -94,20 +117,29 @@ if [ -z "$no_shell" ]; then esac fi -prefix="$(pyenv-prefix "${versions}")" -case "$shell" in -fish ) +if [ -n "${conda_env}" ]; then + # anaconda/miniconda cat </dev/null 2>&1; then" - ;; -esac - prefix="${PYENV_ACTIVATE:-${VIRTUAL_ENV}}" +unset conda_env + +if [ -f "${prefix}/bin/conda" ]; then + if [[ "${prefix}" != "${prefix%/envs/*}" ]]; then + case "$shell" in + bash ) + conda_env="${prefix##*/envs/}" + ;; + zsh ) + conda_env="${prefix##*/envs/}" + ;; + * ) + echo "false" + exit 1 + ;; + esac + else + echo "false" + exit 1 + fi +fi + +if [ -n "${conda_env}" ]; then + echo "if [ -f \"${prefix%/envs/*}/bin/deactivate\" ]; then" +else + case "$shell" in + fish ) + echo "if functions -q deactivate;" + ;; + * ) + echo "if declare -f deactivate 1>/dev/null 2>&1; then" + ;; + esac +fi + if [ -n "$VERBOSE" ]; then echo " echo \"pyenv-virtualenv: deactivate ${prefix##*/}\" 1>&2;" fi @@ -57,24 +83,33 @@ if [ -n "${PYENV_ACTIVATE_SHELL}" ]; then esac fi -case "$shell" in -fish ) +if [ -n "${conda_env}" ]; then cat <&2;"