-
-
Save karrtikr/963469ba74c9b7632d2c43224ffa2f25 to your computer and use it in GitHub Desktop.
Script to deactivate virtual environments for bash or zsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# >>> Virtual env deactivate hook >>> | |
# Same as deactivate in "<venv>/bin/activate" | |
deactivate () { | |
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then | |
PATH="${_OLD_VIRTUAL_PATH:-}" | |
export PATH | |
unset _OLD_VIRTUAL_PATH | |
fi | |
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then | |
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}" | |
export PYTHONHOME | |
unset _OLD_VIRTUAL_PYTHONHOME | |
fi | |
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then | |
hash -r 2> /dev/null | |
fi | |
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then | |
PS1="${_OLD_VIRTUAL_PS1:-}" | |
export PS1 | |
unset _OLD_VIRTUAL_PS1 | |
fi | |
unset VIRTUAL_ENV | |
unset VIRTUAL_ENV_PROMPT | |
if [ ! "${1:-}" = "nondestructive" ] ; then | |
unset -f deactivate | |
fi | |
} | |
# Initialize the variables required by deactivate function | |
_OLD_VIRTUAL_PS1="${PS1:-}" | |
_OLD_VIRTUAL_PATH="$PATH" | |
if [ -n "${PYTHONHOME:-}" ] ; then | |
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}" | |
fi | |
# <<< Virtual env deactivate hook <<< |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment