Skip to content

Instantly share code, notes, and snippets.

@dahlia
Created August 20, 2012 09:07
Show Gist options
  • Save dahlia/3402507 to your computer and use it in GitHub Desktop.
Save dahlia/3402507 to your computer and use it in GitHub Desktop.
[virtualenvwrapper] automatic workon hook on cd
export PROJECTS_HOME="$HOME/Projects"
function has_virtualenv__() {
if [[ "$VIRTUAL_ENV" == "" ]]; then
if [[ $(dirname "`pwd`") == $PROJECTS_HOME ]]; then
venvname=$(basename "`pwd`")
if [[ -d "$WORKON_HOME/$venvname" ]]; then
workon "$venvname"
fi
fi
fi
}
function venv_cd() {
builtin cd "$@" && has_virtualenv__
}
alias cd=venv_cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment