I have a small solution albeit kinda hacky
- Go to the folder which this variable,
$VIRTUALENVWRAPPER_HOOK_DIR
is pointing to. You might need to be in a virtual environment to see that variable, but usually it has the same value as $WORKON_HOME
- In this folder you should see a script called
postactivate
- Add this as the last line in the script:
cdproject
Now what this does is that every time you type workon <project_name>
, this script will run after the virtual environment is activated, and the directory you were working in will switch to the directory for that project.
For more life-cycle hooks, see here!
NOTE
I didn't fully test this to make sure it works no matter how the project was created, but to make sure it works, I recommend creating your virtual environments with mkvirtualenv -a <env_name>
or if the environment exists and with the environment activated, go to it's project folder and run setvirtualenvproject
. Now the next time you try to do workon ...
, the script will kick in and take you to your project folder
Addendum
Since this is a shell script, you can do some fancy tweaks than just that one line. For example you might want to only do something if the activated project has a certain pattern, or part of a certain group of projects. Checkout some of the $VIRTUALENVWRAPPER_*
variables to see what other useful information you can get