Skip to content

Instantly share code, notes, and snippets.

@stringertheory
Forked from clneagu/.bashrc
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stringertheory/fb70af00f0ed09c5c004 to your computer and use it in GitHub Desktop.
Save stringertheory/fb70af00f0ed09c5c004 to your computer and use it in GitHub Desktop.
put this in .bashrc to change to environments created with virtualenvwrapper automatically
# Call virtualenvwrapper's "workon" if .venv exists. This is modified from--
# http://justinlilly.com/python/virtualenv_wrapper_helper.html
# which is linked from--
# http://virtualenvwrapper.readthedocs.org/en/latest/tips.html#automatically-run-workon-when-entering-a-directory
check_virtualenv() {
if [ -e .venv ]; then
env=`cat .venv`
if [ "$env" != "${VIRTUAL_ENV##*/}" ]; then
echo "Found .venv in directory. Calling: workon ${env}"
workon $env
fi
fi
}
venv_cd () {
builtin cd "$@" && check_virtualenv
}
# Call check_virtualenv in case opening directly into a directory (e.g
# when opening a new tab in Terminal.app).
check_virtualenv
# Add the following to ~/.bash_aliases:
# alias cd="venv_cd"
# also, for fun, add something like `pyfiglet "env : $1"` to ~/.virtualenv/preactivate
@gabegaster
Copy link

How is this different from autoenv? as in http://docs.python-guide.org/en/latest/dev/virtualenvs/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment