diff --git a/bin/pyenv-virtualenv-init b/bin/pyenv-virtualenv-init index 080f54b..db15aa3 100755 --- a/bin/pyenv-virtualenv-init +++ b/bin/pyenv-virtualenv-init @@ -9,6 +9,26 @@ set -e [ -n "$PYENV_DEBUG" ] && set -x +resolve_link() { + $(type -p greadlink readlink | head -1) "$1" +} + +abs_dirname() { + local cwd="$(pwd)" + local path="$1" + + while [ -n "$path" ]; do + cd "${path%/*}" + local name="${path##*/}" + path="$(resolve_link "$name" || true)" + done + + pwd + cd "$cwd" +} + +PYENV_VIRTUALENV_INSTALL_PREFIX="$(dirname "$(abs_dirname "$0")")" + print="" for args in "$@" do @@ -65,10 +85,16 @@ fi case "$shell" in fish ) - echo "setenv PYENV_VIRTUALENV_INIT 1;" + cat <&2 + false +fi diff --git a/shims/deactivate b/shims/deactivate new file mode 100755 index 0000000..3a39302 --- /dev/null +++ b/shims/deactivate @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +if [[ "$0" != "${BASH_SOURCE}" ]]; then + eval "$(pyenv sh-deactivate --verbose "$@" || true)" +else + echo "pyenv-virtualenv: deactivate must be sourced. Run 'source deactivate' instead of 'deactivate'" 1>&2 + false +fi diff --git a/test/init.bats b/test/init.bats index b280fdb..0cd7e09 100644 --- a/test/init.bats +++ b/test/init.bats @@ -46,9 +46,11 @@ load test_helper } @test "outputs bash-specific syntax" { + export PYENV_VIRTUALENV_ROOT="${TMP}/pyenv/plugins/pyenv-virtualenv" run pyenv-virtualenv-init - bash assert_success assert_output </dev/null; or true) @@ -112,9 +116,11 @@ EOS } @test "outputs zsh-specific syntax" { + export PYENV_VIRTUALENV_ROOT="${TMP}/pyenv/plugins/pyenv-virtualenv" run pyenv-virtualenv-init - zsh assert_success assert_output <