From 8a837758dcf81bbcc48f4d3280c602706a4e2305 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Mon, 2 Jun 2014 20:16:14 +0900 Subject: [PATCH] activate: invoke `pyenv shell` only if the arguments passed --- README.md | 15 +-------------- bin/pyenv-sh-activate | 9 ++++++--- bin/pyenv-sh-deactivate | 5 ++--- test/activate.bats | 2 -- test/deactivate.bats | 6 ++---- 5 files changed, 11 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index ca530ac..b7baaa0 100644 --- a/README.md +++ b/README.md @@ -86,13 +86,7 @@ version. Some external tools (e.g. [jedi](https://github.com/davidhalter/jedi)) might require you to `activate` the virtualenv. `pyenv activate` lets you to activate the virtualenv into your shell. - $ pyenv activate venv27 - -`pyenv activate` acts almost like following commands. -The activate'd virtualenv will be persisted as _shell_ version. - - $ pyenv shell venv27 - $ source "$(pyenv prefix venv27)/bin/activate" + $ pyenv activate ### Deactivate virtualenv @@ -105,13 +99,6 @@ This is prepared for similality between other `pyenv` commands like `shell` and $ pyenv activate --unset -`pyenv deactivate` acts almost like following commands. -You can also use virtualenv's `deactivate` in place of `pyenv deactivate`, -but be careful with the _shell_ version because it will be persisted even if `deactivate` has invoked. - - $ deactivate - $ pyenv shell --unset - ### Special environment variables You can set certain environment variables to control the pyenv-virtualenv. diff --git a/bin/pyenv-sh-activate b/bin/pyenv-sh-activate index c390459..12e5b79 100755 --- a/bin/pyenv-sh-activate +++ b/bin/pyenv-sh-activate @@ -26,9 +26,8 @@ if [ "$1" = "--unset" ]; then fi versions=("$@") -shell="$(basename "${PYENV_SHELL:-$SHELL}")" - if [ -z "$versions" ]; then + no_shell=1 OLDIFS="$IFS" IFS=: versions=($(pyenv-version-name)) IFS="$OLDIFS" @@ -41,7 +40,11 @@ fi pyenv-virtualenv-prefix "${versions}" 1>/dev/null -echo "pyenv shell \"${versions}\";" +if [ -z "$no_shell" ]; then + echo "pyenv shell \"${versions}\";" +fi + +shell="$(basename "${PYENV_SHELL:-$SHELL}")" case "$shell" in fish ) echo ". \"$(pyenv-prefix "${versions}")/bin/activate.fish\"" ;; * ) echo "source \"$(pyenv-prefix "${versions}")/bin/activate\"" ;; diff --git a/bin/pyenv-sh-deactivate b/bin/pyenv-sh-deactivate index 6383c3e..8cc7568 100755 --- a/bin/pyenv-sh-deactivate +++ b/bin/pyenv-sh-deactivate @@ -11,7 +11,6 @@ set -e shell="$(basename "${PYENV_SHELL:-$SHELL}")" case "$shell" in -fish ) echo "functions -q deactivate; and deactivate;";; -* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate;";; +fish ) echo "functions -q deactivate; and deactivate";; +* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate";; esac -echo "pyenv shell --unset" diff --git a/test/activate.bats b/test/activate.bats index 9f61bc9..405bf39 100644 --- a/test/activate.bats +++ b/test/activate.bats @@ -19,7 +19,6 @@ setup() { assert_success assert_output </dev/null 2>&1 && deactivate; -pyenv shell --unset +declare -f deactivate 1>/dev/null 2>&1 && deactivate EOS } @@ -21,8 +20,7 @@ EOS assert_success assert_output <