Commits

Anonymous committed bce2549

Fix the link to justinlily's cd tip and add the code

Comments (0)

Files changed (1)

 ==================================================
 
 `Justin Lily posted
-<http://justinlilly.com/blog/2009/mar/28/virtualenv-wrapper-helper/>`__
+<http://justinlilly.com/python/virtualenv-wrapper-helper.html>`__
 about some code he added to his shell environment to look at the
 directory each time he runs ``cd``.  If it finds a ``.venv`` file, it
 activates the environment named within.  On leaving that directory,
 the current virtualenv is automatically deactivated.
 
+Simply add this bit to your ``.bashrc``
+
+    has_virtualenv() {
+        if [ -e .venv ]; then
+            workon `cat .venv`
+        fi
+    }
+    venv_cd () {
+        cd "$@" && has_virtualenv
+    }
+    alias cd="venv_cd"
+
 `Harry Marr <http://www.blogger.com/profile/17141199633387157732>`__
 wrote a similar function that works with `git repositories
 <http://hmarr.com/2010/jan/19/making-virtualenv-play-nice-with-git/>`__.