From 11ef0596b5746e9490671869db702a1e9945ab58 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Thu, 31 Jan 2019 02:14:52 +0300 Subject: [PATCH] .bash_logout, .shellrc: Deactivate virtual environment on exit Deactivate python virtual environment on exit from any shell, not only login shell. --- .bash_logout | 5 ----- .shellrc | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.bash_logout b/.bash_logout index ccd81db..ee262d2 100644 --- a/.bash_logout +++ b/.bash_logout @@ -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 diff --git a/.shellrc b/.shellrc index ff08941..9507b48 100644 --- 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; } -- 2.39.2