From 95fa7a35ad92d3706f780c38fb256a6327385045 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 10 May 2015 17:36:03 +0200 Subject: [PATCH 1/2] shell: do not use basename, but bash --- bin/pyenv-sh-activate | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/pyenv-sh-activate b/bin/pyenv-sh-activate index 9af102f..6097ab9 100755 --- a/bin/pyenv-sh-activate +++ b/bin/pyenv-sh-activate @@ -68,7 +68,7 @@ if ! pyenv-virtualenv-prefix "${versions}" 1>/dev/null 2>&1; then exit 1 fi -shell="$(basename "${PYENV_SHELL:-$SHELL}")" +shell="${PYENV_SHELL:-${SHELL##*/}}" case "$shell" in bash ) profile="$HOME/.bash_profile" From 2571a2b97336a25db1af01905d38746033f10502 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 10 May 2015 17:37:23 +0200 Subject: [PATCH 2/2] activate: display setup instructions only with PYENV_VIRTUALENV_INIT=0 This fixes displaying the note, in case "init" has been run manually and/or the init is not in the expected place. It removes the unnecessary calls to "grep". pyenv-virtualenv-init will look at `$PYENV_SHELL` now, too. Tests have been adjusted/fixed. --- bin/pyenv-sh-activate | 22 +++------------------- bin/pyenv-virtualenv-init | 2 +- test/activate.bats | 20 ++++++++++++++++++++ test/init.bats | 1 + 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/bin/pyenv-sh-activate b/bin/pyenv-sh-activate index 6097ab9..323c1b1 100755 --- a/bin/pyenv-sh-activate +++ b/bin/pyenv-sh-activate @@ -69,26 +69,10 @@ if ! pyenv-virtualenv-prefix "${versions}" 1>/dev/null 2>&1; then fi shell="${PYENV_SHELL:-${SHELL##*/}}" -case "$shell" in -bash ) - profile="$HOME/.bash_profile" - ;; -zsh ) - profile="$HOME/.zshrc" - ;; -ksh ) - profile="$HOME/.profile" - ;; -fish ) - profile="$HOME/.config/fish/config.fish" - ;; -* ) - profile="$HOME/.profile" - ;; -esac -# Display setup instruction if 'pyenv virtualenv-init -' is not found in "$profile" -if [ -f "$profile" ] && grep -q 'pyenv init -' "$profile" && ! grep -q 'pyenv virtualenv-init -' "$profile"; then +# Display setup instruction, if pyenv-virtualenv has not been initialized. +# if 'pyenv virtualenv-init -' is not found in "$profile" +if [ -z "$PYENV_VIRTUALENV_INIT" ]; then pyenv-virtualenv-init >&2 || true fi diff --git a/bin/pyenv-virtualenv-init b/bin/pyenv-virtualenv-init index c2ef1cd..9d2be0e 100755 --- a/bin/pyenv-virtualenv-init +++ b/bin/pyenv-virtualenv-init @@ -18,7 +18,7 @@ do fi done -shell="$1" +shell="${1:-$PYENV_SHELL}" if [ -z "$shell" ]; then shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)" shell="${shell##-}" diff --git a/test/activate.bats b/test/activate.bats index 995dcf1..897f189 100644 --- a/test/activate.bats +++ b/test/activate.bats @@ -65,6 +65,11 @@ EOS assert_success assert_output <