Skip to content

Instantly share code, notes, and snippets.

@pymen
Last active December 31, 2015 10:29
Show Gist options
  • Save pymen/7973347 to your computer and use it in GitHub Desktop.
Save pymen/7973347 to your computer and use it in GitHub Desktop.
auto_virtualenv_hooks + wrapper just create .venv file in project dir with 1st line - name of env
############################# HOOKS #####################
#function virtualenv_preexec() {
function virtualenv_precmd(){
FOUND_ENV=0;
x=`pwd`;
while [ "$x" != "/" ] ; do ;
#echo "$x";
if [ `find "$x" -maxdepth 1 -name .venv` ]; then
FOUND_ENV=1;
_VENV_NAME=`cat .venv`
# Check to see if already activated to avoid redundant activating
if [ "$VIRTUAL_ENV" != "$VIRTUALENVWRAPPER_HOOK_DIR/$_VENV_NAME" ]; then
echo "----->" "Activating virtualenv" $_VENV_NAME
workon $_VENV_NAME;
break;
else;
break
fi
x=`dirname "$x"`;
else
x=`dirname "$x"`;
fi;
done
if [ $FOUND_ENV = 1 ]; then
#echo "FOUND"
return;
fi
if [ -z $VIRTUAL_ENV ]; then
#echo "NOT NEED deactivate"
else
echo "<-----" "De-Activating virtualenv" $VIRTUAL_ENV
deactivate
fi
}
add-zsh-hook precmd virtualenv_precmd
#############################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment