Skip to content

Instantly share code, notes, and snippets.

@philroche
Created October 19, 2016 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philroche/72952920176d4d1714e3d29148be607f to your computer and use it in GitHub Desktop.
Save philroche/72952920176d4d1714e3d29148be607f to your computer and use it in GitHub Desktop.
# 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment