Aug 19, 2011

Virtualenv in new Terminal windows/tabs

Just a simple trick to make Terminal open new tabs or windows with the last virtualenv you’ve activated. It does not actually do any wonders, but may be helpful for some. (You’ll need to have virtualenvwrapper installed for this to work.)

Run these commands in your console, they will edit necessary files:

echo 'basename "$VIRTUAL_ENV" > ~/.last_venv' >> $VIRTUALENVWRAPPER_HOOK_DIR/postactivate
echo 'rm ~/.last_venv' >> $VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate

Then open your `~/.bashrc` or `~/.profile` or whatever your shell uses and append:

if [ -e ~/.last_venv ]; then
    workon `cat ~/.last_venv`
fi

No comments: