Skip to content

Instantly share code, notes, and snippets.

@phpdude
Last active August 29, 2015 14:10
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 phpdude/b2ea553c356097988e55 to your computer and use it in GitHub Desktop.
Save phpdude/b2ea553c356097988e55 to your computer and use it in GitHub Desktop.
Auto activate virtualenv & activate_env alias
alias activate_env='ENVDIR=""; for d in *; do if [ -f $d/bin/activate ]; then ENVDIR="$d/bin/activate"; fi; done; if [ "$ENVDIR" ]; then source $ENVDIR; else echo Virtualenv dir not found; fi'
ENVDIR=""; for d in *; do if [ -f $d/bin/activate ]; then ENVDIR="$d/bin/activate"; fi; done; if [ "$ENVDIR" ]; then source $ENVDIR; fi
@dude /# activate_env
Virtualenv dir not found
@dude /# cd /WWW/Python/My/AskGuru
@dude /WWW/Python/My/AskGuru# activate_env
(env)@dude /WWW/Python/My/AskGuru#
(env)@dude /Users/WWW/Python/My/AskGuru# echo $ENVDIR
env/bin/activate
@phpdude
Copy link
Author

phpdude commented Nov 27, 2014

Simple drop this code to your ~/.profile file and on console tab initialization virtualenv will be activated automatically. Or you can use shell alias activate_env manually.

On bash intialization helper doesn't show anything if virtualenv not found, but alias will show error message if virtualenv not found.

Also you have $ENVDIR env variable as bonus :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment