diff --git a/README.rst b/README.rst index 4dc482e..7f1180d 100644 --- a/README.rst +++ b/README.rst @@ -154,8 +154,15 @@ Convenience Commands (added in v.1.2.4) Hooks ------ +---------- To run some commands after ``mkvirtualenv`` you can use hooks. First you need to define ``VIRTUALENVWRAPPER_HOOK_DIR`` variable. If it is -set ``mkvirtualenv`` will run ``postmkvirtualenv.bat`` script from -that directory. +set ``mkvirtualenv`` will run ``postmkvirtualenv.bat`` script and +``workon`` and ``deactivate`` will run ``postactivate.bat`` and +``postdeactivate.bat`` scripts from that directory. + +To run some commands after ``workon`` or ``deactivate`` that are +specific to a virtual environment, you can create ``postactivate.bat`` +or ``postdeactivate.bat`` scripts in the virtual environment's ``Scripts`` +directory. + diff --git a/scripts/workon.bat b/scripts/workon.bat index b5486d4..62ed55e 100644 --- a/scripts/workon.bat +++ b/scripts/workon.bat @@ -34,9 +34,21 @@ if not "%1"=="" ( ) if defined VIRTUAL_ENV ( + SET "VIRTUAL_ENV_POSTDEACTIVATE=%VIRTUAL_ENV%\Scripts\postdeactivate.bat" call "%VIRTUAL_ENV%\Scripts\deactivate.bat" + if exist "%VIRTUAL_ENV_POSTDEACTIVATE%" ( + call "%VIRTUAL_ENV_POSTDEACTIVATE%" + ) + SET VIRTUAL_ENV_POSTDEACTIVATE= + if defined VIRTUALENVWRAPPER_HOOK_DIR ( + if exist "%VIRTUALENVWRAPPER_HOOK_DIR%\postdeactivate.bat" ( + call "%VIRTUALENVWRAPPER_HOOK_DIR%\postdeactivate.bat" + ) + ) + ) + pushd "%WORKON_HOME%" 2>NUL && popd if errorlevel 1 ( mkdir "%WORKON_HOME%" @@ -71,4 +83,14 @@ if exist "%WORKON_HOME%\%VENV%\%VIRTUALENVWRAPPER_PROJECT_FILENAME%" ( ) ) +if defined VIRTUALENVWRAPPER_HOOK_DIR ( + if exist "%VIRTUALENVWRAPPER_HOOK_DIR%\postactivate.bat" ( + call "%VIRTUALENVWRAPPER_HOOK_DIR%\postactivate.bat" + ) +) + +if exist "%WORKON_HOME%\%VENV%\Scripts\postactivate.bat" ( + call "%WORKON_HOME%\%VENV%\Scripts\postactivate.bat" +) + :END