Skip to content

Instantly share code, notes, and snippets.

@gorhack
Last active January 8, 2016 16:34
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 gorhack/d554e7065e061f5b7284 to your computer and use it in GitHub Desktop.
Save gorhack/d554e7065e061f5b7284 to your computer and use it in GitHub Desktop.
Enter/Exit virtual environment when workon/deactiavated
#!/bin/bash
# This hook is sourced after every virtualenv is activated.
PS1="$_OLD_VIRTUAL_PS1"
PROJECT_DIR="$HOME/Documents/Development/virtualenvs/$(basename $VIRTUAL_ENV)"
if [ -d $PROJECT_DIR ]; then
# If we aren't already within the project dir, cd into it
if [[ ! `pwd` == "$PROJECT_DIR*" ]]; then
export PRE_VENV_ACTIVATE_DIR=`pwd`
cd "$PROJECT_DIR"
fi
fi
unset PROJECT_DIR
#!/bin/bash
# This hook is sourced after every virtualenv is deactivated.
if [ $PRE_VENV_ACTIVATE_DIR ]; then
cd $PRE_VENV_ACTIVATE_DIR
unset PRE_VENV_ACTIVATE_DIR
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment