robbyrussell/oh-my-zsh — pull request #1494 by rhlobo (2012-12-15 22:35:04+00:00)
Title: Modified virtualenvwrapper plugin to prevent a possible circular execution loop

Bug Fix
======

Modified *virtualenvwrapper plugin* to prevent a possible circular execution loop that may happen when activating an environment.

### Motivation

In some environments, the `workon` command called inside `workon_cwd` function causes a circular loop calling the function again, until `zsh` complains either of `job table full` or `recursion limit exceeded`. Although the *virtualenv* ends up activated, this consumes processing and leaves the user waiting (annoyed) for a while until the error occurs.

### Scenario and Solution

The `workon_cwd` function already makes some checks before activating a *virtualenv*, then - if it is successfully done - it sets the environment variable `CD_VIRTUAL_ENV`, which is used internally by the plugin.

The solution found was to add another verification using the environment variable, in order to check if the *virtualenv* is being set, and then, if not so, set the variable just before calling `workon`, making sure to unset it if something goes wrong.