# Add the following to your ~/.bashrc making sure to set $WORKON_HOME variable
function cd() {
builtin cd "$1"
absolute_path=$(readlink -m "$1")
base_path=$(basename "$absolute_path")
if [ -z "$VIRTUAL_ENV" ]
then
if [ -d "$WORKON_HOME/$base_path" ]
then
echo "Activating $base_path virtualenv"
# Control will enter here if $DIRECTORY exists.
source "$WORKON_HOME/$base_path/bin/activate"
fi
fi
}