Virtualenv Wrapper Helper

A bit inspired by all the awesome stuff happening at PyCon, I've done a bit of hacking on my shell to improve the use of virtualenvwrapper. Remembering to checkout the correct virtualenv is a bit of a pain, especially when you move around your filesystem as much as I do. To fix this, I've written a bit of code for my bash prompt to ease the pain. It works by looking for the existence of a .venv file every time you cd into a directory. If it exists, it will attempt to workon the contents of the file, which should be the project name. For instance, for my oebfare project, the file contains the name of my virtualenv. Due to this, the following is possible:

# prompt edited to save space
:12:02 AM: (~/Code/django) jlilly$ cd baconfile/
(baconfile):12:03 AM: (~/Code/django/baconfile) (master) jlilly$ cd ..
(baconfile):12:03 AM: (~/Code/django) jlilly$ cd oebfare/
(oebfare):12:03 AM: (~/Code/django/oebfare) (master) jlilly$

When we cd into the baconfile dir, we get the virtualenv for baconfile. We can cd out of that directory and about the filesystem, but when we enter a directory that contains a different .venv file, we get a different virtualenv.

© 2012 - 2022 · Home — Theme Simpleness