Skip to content

Instantly share code, notes, and snippets.

@phpdude phpdude/.profile
Last active Aug 29, 2015

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.