Created
April 26, 2014 19:16
-
-
Save mythmon/11328513 to your computer and use it in GitHub Desktop.
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
export AUTO_VENV_LAST_DIR="" | |
chpwd_auto_venv () { | |
dir=$(pwd) | |
last="" | |
while true; do | |
if [[ -f $dir/.venv ]]; then | |
if [[ $dir = $AUTO_VENV_LAST_DIR ]]; then | |
return 0 | |
fi | |
source $dir/.venv | |
v_activate | |
export AUTO_VENV_LAST_DIR=$dir | |
return 0 | |
fi | |
if [[ -n $last ]]; then | |
if [[ -n "$AUTO_VENV_LAST_DIR" ]]; then | |
source "${AUTO_VENV_LAST_DIR}/.venv" | |
v_deactivate | |
export AUTO_VENV_LAST_DIR="" | |
return 0 | |
fi | |
return 0 | |
fi | |
dir=$(dirname $dir) | |
if [[ "/" = $dir ]]; then | |
last=1 | |
fi | |
done | |
} | |
add-zsh-hook chpwd chpwd_auto_venv | |
chpwd_auto_venv | |
#EOF vim: ft=zsh |
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
#!/bin/bash | |
if [[ -f .venv ]]; then | |
echo "There is already a .venv file here, not overwriting." | |
exit 1 | |
fi | |
virtualenv2 --distribute . | |
echo '#!/bin/bash | |
DIR=$(dirname $0) | |
source $DIR/bin/activate | |
v_activate() { | |
} | |
v_deactivate() { | |
deactivate | |
}' > .venv | |
echo "Made .venv for automatic activation." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment