mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-08 11:33:55 -05:00
Change prompt after activate (#52)
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
unset DEACTIVATE
|
||||
unset FORCE
|
||||
unset QUIET
|
||||
unset VERBOSE
|
||||
@@ -26,9 +25,6 @@ while [ $# -gt 0 ]; do
|
||||
echo --unset
|
||||
exec pyenv-virtualenvs --bare
|
||||
;;
|
||||
"-d" | "--deactivate" )
|
||||
DEACTIVATE=1
|
||||
;;
|
||||
"-f" | "--force" )
|
||||
FORCE=1
|
||||
;;
|
||||
@@ -36,8 +32,7 @@ while [ $# -gt 0 ]; do
|
||||
QUIET=1
|
||||
;;
|
||||
"--unset" )
|
||||
echo "pyenv deactivate"
|
||||
exit
|
||||
exec pyenv-sh-deactivate
|
||||
;;
|
||||
"-v" | "--verbose" )
|
||||
VERBOSE=1
|
||||
@@ -115,9 +110,7 @@ if [ -z "$PYENV_VIRTUALENV_INIT" ]; then
|
||||
pyenv-virtualenv-init >&2 || true
|
||||
fi
|
||||
|
||||
if [ -n "${DEACTIVATE}" ]; then
|
||||
pyenv-sh-deactivate ${QUIET+--quiet} ${VERBOSE+--verbose}
|
||||
fi
|
||||
pyenv-sh-deactivate --quiet ${VERBOSE+--verbose} || true
|
||||
|
||||
echo "pyenv-virtualenv: activate ${venv}" 1>&2
|
||||
|
||||
@@ -192,3 +185,21 @@ EOS
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
PYENV_VIRTUALENV_DISABLE_PROMPT="${PYENV_VIRTUALENV_DISABLE_PROMPT:-${PYENV_VIRTUAL_ENV_DISABLE_PROMPT}}"
|
||||
PYENV_VIRTUALENV_DISABLE_PROMPT="${PYENV_VIRTUALENV_DISABLE_PROMPT:-${VIRTUAL_ENV_DISABLE_PROMPT}}"
|
||||
|
||||
if [ -z "${PYENV_VIRTUALENV_DISABLE_PROMPT}" ]; then
|
||||
case "${shell}" in
|
||||
fish )
|
||||
echo "pyenv-virtualenv: prompt changing not work for fish." 1>&2
|
||||
;;
|
||||
* )
|
||||
echo "pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior." 1>&2
|
||||
cat <<EOS
|
||||
export _OLD_VIRTUAL_PS1="\${PS1}";
|
||||
export PS1="(${venv}) \${PS1}";
|
||||
EOS
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
@@ -114,3 +114,17 @@ EOS
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
case "${shell}" in
|
||||
fish )
|
||||
:
|
||||
;;
|
||||
* )
|
||||
if [ -n "${_OLD_VIRTUAL_PS1}" ]; then
|
||||
cat <<EOS
|
||||
export PS1='${_OLD_VIRTUAL_PS1}';
|
||||
unset _OLD_VIRTUAL_PS1;
|
||||
EOS
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -104,7 +104,7 @@ fish )
|
||||
function _pyenv_virtualenv_hook --on-event fish_prompt;
|
||||
set -l ret \$status
|
||||
if [ -n "\$VIRTUAL_ENV" ]
|
||||
pyenv activate --deactivate --quiet; or pyenv deactivate --quiet; or true
|
||||
pyenv activate --quiet; or pyenv deactivate --quiet; or true
|
||||
else
|
||||
pyenv activate --quiet; or true
|
||||
end
|
||||
@@ -128,7 +128,7 @@ if [[ "$shell" != "fish" ]]; then
|
||||
cat <<EOS
|
||||
local ret=\$?
|
||||
if [ -n "\$VIRTUAL_ENV" ]; then
|
||||
eval "\$(pyenv sh-activate --deactivate --quiet || pyenv sh-deactivate --quiet || true)" || true
|
||||
eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true
|
||||
else
|
||||
eval "\$(pyenv sh-activate --quiet || true)" || true
|
||||
fi
|
||||
|
||||
@@ -5,6 +5,10 @@ load test_helper
|
||||
setup() {
|
||||
export HOME="${TMP}"
|
||||
export PYENV_ROOT="${TMP}/pyenv"
|
||||
unset PYTHONHOME
|
||||
unset PYENV_VIRTUALENV_DISABLE_PROMPT
|
||||
unset PYENV_VIRTUAL_ENV_DISABLE_PROMPT
|
||||
unset VIRTUAL_ENV_DISABLE_PROMPT
|
||||
}
|
||||
|
||||
@test "activate virtualenv from current version" {
|
||||
@@ -22,9 +26,13 @@ setup() {
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
false
|
||||
pyenv-virtualenv: activate venv
|
||||
unset PYENV_DEACTIVATE;
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1}";
|
||||
export PS1="(venv) \${PS1}";
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -43,9 +51,13 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
false
|
||||
pyenv-virtualenv: activate venv
|
||||
unset PYENV_DEACTIVATE;
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1}";
|
||||
export PS1="(venv) \${PS1}";
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -69,11 +81,15 @@ EOS
|
||||
|
||||
eval "\$(pyenv virtualenv-init -)"
|
||||
|
||||
false
|
||||
pyenv-virtualenv: activate venv
|
||||
export PYENV_VERSION="venv";
|
||||
export PYENV_ACTIVATE_SHELL=1;
|
||||
unset PYENV_DEACTIVATE;
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1}";
|
||||
export PS1="(venv) \${PS1}";
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -92,9 +108,11 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
false
|
||||
pyenv-virtualenv: activate venv
|
||||
set -e PYENV_DEACTIVATE;
|
||||
setenv VIRTUAL_ENV "${PYENV_ROOT}/versions/venv";
|
||||
pyenv-virtualenv: prompt changing not work for fish.
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -118,11 +136,13 @@ EOS
|
||||
|
||||
status --is-interactive; and . (pyenv virtualenv-init -|psub)
|
||||
|
||||
false
|
||||
pyenv-virtualenv: activate venv
|
||||
setenv PYENV_VERSION "venv";
|
||||
setenv PYENV_ACTIVATE_SHELL 1;
|
||||
set -e PYENV_DEACTIVATE;
|
||||
setenv VIRTUAL_ENV "${PYENV_ROOT}/versions/venv";
|
||||
pyenv-virtualenv: prompt changing not work for fish.
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -139,11 +159,15 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
false
|
||||
pyenv-virtualenv: activate venv27
|
||||
export PYENV_VERSION="venv27";
|
||||
export PYENV_ACTIVATE_SHELL=1;
|
||||
unset PYENV_DEACTIVATE;
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1}";
|
||||
export PS1="(venv27) \${PS1}";
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -165,11 +189,15 @@ EOS
|
||||
|
||||
eval "\$(pyenv virtualenv-init -)"
|
||||
|
||||
false
|
||||
pyenv-virtualenv: activate venv27
|
||||
export PYENV_VERSION="venv27";
|
||||
export PYENV_ACTIVATE_SHELL=1;
|
||||
unset PYENV_DEACTIVATE;
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1}";
|
||||
export PS1="(venv27) \${PS1}";
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -186,11 +214,13 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
false
|
||||
pyenv-virtualenv: activate venv27
|
||||
setenv PYENV_VERSION "venv27";
|
||||
setenv PYENV_ACTIVATE_SHELL 1;
|
||||
set -e PYENV_DEACTIVATE;
|
||||
setenv VIRTUAL_ENV "${PYENV_ROOT}/versions/venv27";
|
||||
pyenv-virtualenv: prompt changing not work for fish.
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -212,20 +242,27 @@ EOS
|
||||
|
||||
status --is-interactive; and . (pyenv virtualenv-init -|psub)
|
||||
|
||||
false
|
||||
pyenv-virtualenv: activate venv27
|
||||
setenv PYENV_VERSION "venv27";
|
||||
setenv PYENV_ACTIVATE_SHELL 1;
|
||||
set -e PYENV_DEACTIVATE;
|
||||
setenv VIRTUAL_ENV "${PYENV_ROOT}/versions/venv27";
|
||||
pyenv-virtualenv: prompt changing not work for fish.
|
||||
EOS
|
||||
}
|
||||
|
||||
@test "unset invokes deactivate" {
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"
|
||||
export PYENV_ACTIVATE_SHELL=
|
||||
|
||||
run pyenv-sh-activate --unset
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
pyenv deactivate
|
||||
pyenv-virtualenv: deactivate venv
|
||||
export PYENV_DEACTIVATE="${PYENV_ROOT}/versions/venv";
|
||||
unset VIRTUAL_ENV;
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -315,11 +352,15 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
false
|
||||
pyenv-virtualenv: activate venv27
|
||||
export PYENV_VERSION="venv27:2.7.10";
|
||||
export PYENV_ACTIVATE_SHELL=1;
|
||||
unset PYENV_DEACTIVATE;
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1}";
|
||||
export PS1="(venv27) \${PS1}";
|
||||
EOS
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ load test_helper
|
||||
setup() {
|
||||
export HOME="${TMP}"
|
||||
export PYENV_ROOT="${TMP}/pyenv"
|
||||
unset _OLD_VIRTUAL_PYTHONHOME
|
||||
unset _OLD_VIRTUAL_PS1
|
||||
}
|
||||
|
||||
@test "activate conda root from current version" {
|
||||
@@ -23,10 +25,14 @@ setup() {
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
false
|
||||
pyenv-virtualenv: activate anaconda-2.3.0
|
||||
unset PYENV_DEACTIVATE;
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/anaconda-2.3.0";
|
||||
export CONDA_DEFAULT_ENV="root";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1}";
|
||||
export PS1="(anaconda-2.3.0) \${PS1}";
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -46,10 +52,12 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
false
|
||||
pyenv-virtualenv: activate anaconda-2.3.0
|
||||
set -e PYENV_DEACTIVATE;
|
||||
setenv VIRTUAL_ENV "${TMP}/pyenv/versions/anaconda-2.3.0";
|
||||
setenv CONDA_DEFAULT_ENV "root";
|
||||
pyenv-virtualenv: prompt changing not work for fish.
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -68,12 +76,16 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
false
|
||||
pyenv-virtualenv: activate miniconda-3.9.1
|
||||
export PYENV_VERSION="miniconda-3.9.1";
|
||||
export PYENV_ACTIVATE_SHELL=1;
|
||||
unset PYENV_DEACTIVATE;
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/miniconda-3.9.1";
|
||||
export CONDA_DEFAULT_ENV="root";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1}";
|
||||
export PS1="(miniconda-3.9.1) \${PS1}";
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -93,10 +105,14 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
false
|
||||
pyenv-virtualenv: activate anaconda-2.3.0/envs/foo
|
||||
unset PYENV_DEACTIVATE;
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/anaconda-2.3.0/envs/foo";
|
||||
export CONDA_DEFAULT_ENV="foo";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1}";
|
||||
export PS1="(anaconda-2.3.0/envs/foo) \${PS1}";
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -115,11 +131,15 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
false
|
||||
pyenv-virtualenv: activate miniconda-3.9.1/envs/bar
|
||||
export PYENV_VERSION="miniconda-3.9.1/envs/bar";
|
||||
export PYENV_ACTIVATE_SHELL=1;
|
||||
unset PYENV_DEACTIVATE;
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/miniconda-3.9.1/envs/bar";
|
||||
export CONDA_DEFAULT_ENV="bar";
|
||||
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
|
||||
export _OLD_VIRTUAL_PS1="\${PS1}";
|
||||
export PS1="(miniconda-3.9.1/envs/bar) \${PS1}";
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ export PYENV_VIRTUALENV_INIT=1;
|
||||
_pyenv_virtualenv_hook() {
|
||||
local ret=\$?
|
||||
if [ -n "\$VIRTUAL_ENV" ]; then
|
||||
eval "\$(pyenv sh-activate --deactivate --quiet || pyenv sh-deactivate --quiet || true)" || true
|
||||
eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true
|
||||
else
|
||||
eval "\$(pyenv sh-activate --quiet || true)" || true
|
||||
fi
|
||||
@@ -77,7 +77,7 @@ setenv PYENV_VIRTUALENV_INIT 1;
|
||||
function _pyenv_virtualenv_hook --on-event fish_prompt;
|
||||
set -l ret \$status
|
||||
if [ -n "\$VIRTUAL_ENV" ]
|
||||
pyenv activate --deactivate --quiet; or pyenv deactivate --quiet; or true
|
||||
pyenv activate --quiet; or pyenv deactivate --quiet; or true
|
||||
else
|
||||
pyenv activate --quiet; or true
|
||||
end
|
||||
@@ -96,7 +96,7 @@ export PYENV_VIRTUALENV_INIT=1;
|
||||
_pyenv_virtualenv_hook() {
|
||||
local ret=\$?
|
||||
if [ -n "\$VIRTUAL_ENV" ]; then
|
||||
eval "\$(pyenv sh-activate --deactivate --quiet || pyenv sh-deactivate --quiet || true)" || true
|
||||
eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true
|
||||
else
|
||||
eval "\$(pyenv sh-activate --quiet || true)" || true
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user