Last active
September 19, 2016 20:03
-
-
Save qoda/3236821 to your computer and use it in GitHub Desktop.
Virtualenv Auto-activate
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
cd () | |
{ | |
builtin cd "$@" | |
RETVAL=$? | |
# Test for successful real cd: | |
if [ 0 -ne $RETVAL ]; then | |
return $RETVAL | |
fi | |
# Deactivate once I move outside the virtualenv directory or | |
# do nothing when I'm still in this same virtualenv directory | |
# (Assuming no one nests virtualenvs....) | |
if [ ! -z "$VIRTUAL_ENV" ]; then | |
if [ "$PWD" = "${PWD#$VIRTUAL_ENV}" ]; then | |
deactivate | |
echo | |
echo "Deactivating virtualenv..." | |
else | |
return 0 | |
fi | |
fi | |
# "Detect" virtualenv files: | |
if [ -r "ve/bin/activate" ]; then | |
if head -n 1 "ve/bin/activate" | grep -q 'source bin/activate' > /dev/null; then | |
source "ve/bin/activate" | |
echo | |
echo "Activating virtualenv..." | |
fi | |
fi | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment