From 0b5e0cf592976670d432ac03c7e93deb9457de45 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Fri, 4 Jul 2014 20:27:55 +0900 Subject: [PATCH] Unset shell version only if the `deactivate` has invoked --- bin/pyenv-sh-deactivate | 23 +++++++++++++++-------- test/deactivate.bats | 4 ++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/bin/pyenv-sh-deactivate b/bin/pyenv-sh-deactivate index 85e2803..a2a1d1f 100755 --- a/bin/pyenv-sh-deactivate +++ b/bin/pyenv-sh-deactivate @@ -10,10 +10,24 @@ set -e [ -n "$PYENV_DEBUG" ] && set -x shell="$(basename "${PYENV_SHELL:-$SHELL}")" +case "$shell" in +fish ) + echo "if functions -q deactivate" + ;; +* ) + echo "if declare -f deactivate 1>/dev/null 2>&1; then" + ;; +esac + +if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then + # Backward compatibility issue + # https://github.com/yyuu/pyenv-virtualenv/issues/26 + echo " pyenv shell --unset;" +fi + case "$shell" in fish ) cat </dev/null 2>&1; then export PYENV_DEACTIVATE="\$VIRTUAL_ENV"; deactivate; fi; EOS ;; esac - -if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then - # Backward compatibility issue - # https://github.com/yyuu/pyenv-virtualenv/issues/26 - echo "pyenv shell --unset;" -fi diff --git a/test/deactivate.bats b/test/deactivate.bats index 1f8331a..67faa2f 100644 --- a/test/deactivate.bats +++ b/test/deactivate.bats @@ -28,10 +28,10 @@ EOS assert_success assert_output </dev/null 2>&1; then + pyenv shell --unset; export PYENV_DEACTIVATE="\$VIRTUAL_ENV"; deactivate; fi; -pyenv shell --unset; EOS } @@ -57,10 +57,10 @@ EOS assert_success assert_output <