Skip to content

Instantly share code, notes, and snippets.

@yrik
Created September 7, 2011 02:34
Show Gist options
  • Save yrik/1199612 to your computer and use it in GitHub Desktop.
Save yrik/1199612 to your computer and use it in GitHub Desktop.
PREVPWD=`pwd`
PREVENV_PATH=
PREV_PS1=
PREV_PATH=
handle_virtualenv(){
if [ "$PWD" != "$PREVPWD" ]; then
PREVPWD="$PWD";
if [ -n "$PREVENV_PATH" ]; then
if [ "`echo "$PWD" | grep -c $PREVENV_PATH`" = "0" ]; then
deactivate
echo "> Virtualenv `basename $PWD` deactivated"
PS1=$PREV_PS1
PATH=$PREV_PATH
PREVENV_PATH=
fi
fi
# activate virtualenv dynamically
if [ -e "$PWD/.env" ] && [ "$PWD" != "$PREVENV_PATH" ]; then
PREV_PS1="$PS1"
PREV_PATH="$PATH"
PREVENV_PATH="$PWD"
source $PWD/.env/bin/activate
echo "> Virtualenv `basename $PWD` activated"
fi
fi
}
export PROMPT_COMMAND=handle_virtualenv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment