Skip to content

Instantly share code, notes, and snippets.

@akheron
Created November 14, 2012 09:39
Show Gist options
  • Select an option

  • Save akheron/4071242 to your computer and use it in GitHub Desktop.

Select an option

Save akheron/4071242 to your computer and use it in GitHub Desktop.
Change to virtualenv when cd'ing to a directory
# If a directory contains a file named .venv, read its contents and activate
# the corresponding virtualenv.
venv_cd() {
local venv
if builtin cd "$@"; then
if [ -e .venv ]; then
venv=$(cat .venv)
if [ -z "$VIRTUAL_ENV" ]; then
workon "$venv" || true
elif [ "$(basename $VIRTUAL_ENV)" != "$venv" ]; then
workon "$venv" || true
fi
fi
else
return $?
fi
}
alias cd="venv_cd"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment