Created
August 2, 2012 18:09
-
-
Save lucasvo/3239248 to your computer and use it in GitHub Desktop.
Automatically activate your python virtualenvironment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function auto_activate { | |
SEARCHPATH=`pwd` | |
function activate_env { | |
# ZSH outputs errors for the ls * command if you don't disable the nomatch output | |
unsetopt nomatch 2>/dev/null | |
ls $SEARCHPATH/*/bin/activate > /dev/null 2> /dev/null | |
if [ "$?" = '0' ]; then | |
deactivate > /dev/null 2> /dev/null | |
source $SEARCHPATH/*/bin/activate | |
return | |
else | |
SEARCHPATH=$(dirname "$SEARCHPATH") | |
if [ "$SEARCHPATH" = "/" ]; then | |
return | |
fi | |
activate_env | |
return $? | |
fi | |
} | |
unset $SEARCHPATH | |
activate_env | |
setopt nomatch | |
} | |
auto_activate | |
alias autoactivate="auto_activate" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- activate 2012-07-11 15:25:02.000000000 -0700 | |
+++ activate_p 2012-08-02 11:18:50.000000000 -0700 | |
@@ -62,7 +62,7 @@ | |
# see http://www.zetadev.com/software/aspen/ | |
PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1" | |
else | |
- PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1" | |
+ PS1="(myproject)$PS1" | |
fi | |
fi | |
export PS1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good work 👍