Skip to content

Instantly share code, notes, and snippets.

@lucasvo
Created August 2, 2012 18:09
Show Gist options
  • Save lucasvo/3239248 to your computer and use it in GitHub Desktop.
Save lucasvo/3239248 to your computer and use it in GitHub Desktop.
Automatically activate your python virtualenvironment
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"
--- 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
Copy link

ghost commented Aug 21, 2014

Good work 👍

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