-
-
Save disouzam/80b8c004a6880fecac8395ad7f2a1d49 to your computer and use it in GitHub Desktop.
Script to deactivate virtual environments for bash or zsh
This file contains hidden or 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
Link to the original gist: https://github.com/microsoft/vscode-python/wiki/Fixing-%22deactivate%22-command-for-Virtual-Environments