Skip to content

Instantly share code, notes, and snippets.

@mythmon
Created April 26, 2014 19:16
Show Gist options
  • Save mythmon/11328513 to your computer and use it in GitHub Desktop.
Save mythmon/11328513 to your computer and use it in GitHub Desktop.
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
#!/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