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.
This commit is contained in:
Daniel Hahler
2015-05-10 17:37:23 +02:00
parent 95fa7a35ad
commit 2571a2b973
4 changed files with 25 additions and 20 deletions

View File

@@ -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