Skip to content

Instantly share code, notes, and snippets.

@ajpen
Forked from Willyfrog/virtualenv-auto-activate.sh
Last active May 7, 2018 16:14
Show Gist options
  • Save ajpen/901b801c4019d0d9a5bfa5edf9d14db8 to your computer and use it in GitHub Desktop.
Save ajpen/901b801c4019d0d9a5bfa5edf9d14db8 to your computer and use it in GitHub Desktop.
virtualenv-auto-activate-auto-deactivate with support for existing custom PROMPT_COMMAND
#!/bin/bash
_virtualenv_auto_activate() {
if [ -e ".env" ]; then
# Check to see if already activated to avoid redundant activating
if [ "$VIRTUAL_ENV" = "" ]; then
source .env/bin/activate
fi
else
if [ "$VIRTUAL_ENV" != "" ]; then
deactivate
fi
fi
}
export PROMPT_COMMAND="_virtualenv_auto_activate; $PROMPT_COMMAND"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment