]> git.phdru.name Git - dotfiles.git/commitdiff
.bash_logout, .shellrc: Deactivate virtual environment on exit
authorOleg Broytman <phd@phdru.name>
Wed, 30 Jan 2019 23:14:52 +0000 (02:14 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 30 Jan 2019 23:14:52 +0000 (02:14 +0300)
Deactivate python virtual environment on exit from any shell,
not only login shell.

.bash_logout
.shellrc

index ccd81db926157aba9e1c23cb742583fb633a393c..ee262d25fa0e592f90074284e5845535ae827cf0 100644 (file)
@@ -1,10 +1,5 @@
 # ~/.bash_logout: executed by bash(1) when login shell exits.
 
-# Clean up python virtual environment on exit
-# See https://virtualenvwrapper.readthedocs.io/en/latest/tips.html#clean-up-environments-on-exit
-
-[ "$VIRTUAL_ENV" ] && deactivate
-
 # when leaving the console clear the screen to increase privacy
 
 if [ "$SHLVL" = 1 ]; then
index ff089415d0369a3b135b17ab5f2a73b133d22327..9507b48ea3f6fb3ac02f56d2627a0db1a0aa5ed4 100644 (file)
--- a/.shellrc
+++ b/.shellrc
@@ -164,6 +164,11 @@ if test -n "$BASH_VERSION"; then
       . "$VIRTUAL_ENV/bin/activate"
    fi
 
+   # Clean up python virtual environment on exit
+   # See https://virtualenvwrapper.readthedocs.io/en/latest/tips.html#clean-up-environments-on-exit
+
+   trap '[ "$VIRTUAL_ENV" ] && deactivate' EXIT
+
 elif test -n "$KSH_VERSION" -o -n "$FCEDIT"; then
    back() { cd - "$@"; }
    j() { jobs; }