Allow activating first version of virtualenv even if there are multiple versions in pyenv (#105)

This commit is contained in:
Yamashita, Yuu
2015-11-08 05:18:25 +00:00
parent ce6ec4f173
commit f7d1aa7d94
3 changed files with 79 additions and 85 deletions

View File

@@ -27,51 +27,44 @@ while [ $# -gt 0 ]; do
shift 1
done
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
prefix="${VIRTUAL_ENV:-${PYENV_ACTIVATE}}"
if [ -z "${prefix}" ]; then
[ -n "$QUIET" ] || echo "pyenv-virtualenv: no virtualenv has been activated." 1>&2
if [ -z "${VIRTUAL_ENV}" ]; then
if [ -z "$QUIET" ]; then
echo "pyenv-virtualenv: no virtualenv has been activated." 1>&2
fi
echo "false"
exit 1
fi
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
prefix="${VIRTUAL_ENV}"
if [[ "${prefix}" != "${prefix%/envs/*}" ]]; then
version="$(basename "${prefix%/envs/*}")/envs/${prefix##*/}"
venv="$(basename "${prefix%/envs/*}")/envs/${prefix##*/}"
else
version="${prefix##*/}"
venv="${prefix##*/}"
fi
echo "pyenv-virtualenv: deactivate ${version}" 1>&2
echo "pyenv-virtualenv: deactivate ${venv}" 1>&2
if [ -n "${PYENV_ACTIVATE_SHELL}" ]; then
# shell version set in pyenv-sh-activate should be unset
# https://github.com/yyuu/pyenv-virtualenv/issues/61
echo "pyenv shell --unset;"
case "$shell" in
fish )
echo "set -e PYENV_ACTIVATE_SHELL;"
cat <<EOS
set -e PYENV_VERSION;
set -e PYENV_ACTIVATE_SHELL;
EOS
;;
* )
echo "unset PYENV_ACTIVATE_SHELL;"
cat <<EOS
unset PYENV_VERSION;
unset PYENV_ACTIVATE_SHELL;
EOS
;;
esac
fi
case "${shell}" in
fish )
cat <<EOS
setenv PYENV_DEACTIVATE "$prefix";
set -e PYENV_ACTIVATE;
EOS
;;
* )
cat <<EOS
export PYENV_DEACTIVATE="$prefix";
unset PYENV_ACTIVATE;
EOS
;;
esac
# virtualenv/pyvenv
case "${shell}" in
fish )