|
| 1 | +# |
| 2 | +# Create the default hooks, if they do not exist on startup. |
| 3 | +# |
| 4 | + |
| 5 | +# Create a hook script |
| 6 | +# |
| 7 | +# Usage: virtualenvwrapper_make_hook filename comment |
| 8 | +# |
| 9 | +function virtualenvwrapper_make_hook () { |
| 10 | + filename="$1" |
| 11 | + comment="$2" |
| 12 | + if [ ! -f "$filename" ] |
| 13 | + then |
| 14 | + #echo "Creating $filename" |
| 15 | + cat - > "$filename" <<EOF |
| 16 | +#!/bin/sh |
| 17 | +# $comment |
| 18 | +
|
| 19 | +EOF |
| 20 | + fi |
| 21 | + if [ ! -x "$filename" ] |
| 22 | + then |
| 23 | + chmod +x "$filename" |
| 24 | + fi |
| 25 | +} |
| 26 | + |
| 27 | +# initialize |
| 28 | +virtualenvwrapper_make_hook "$WORKON_HOME/preinitialize" \ |
| 29 | + "This hook is run early in the startup phase when loading virtualenvwrapper.sh." |
| 30 | +virtualenvwrapper_make_hook "$WORKON_HOME/postinitialize" \ |
| 31 | + "This hook is run later in the startup phase when loading virtualenvwrapper.sh." |
| 32 | +# mkvirtualenv |
| 33 | +virtualenvwrapper_make_hook "$WORKON_HOME/premkvirtualenv" \ |
| 34 | + "This hook is run after a new virtualenv is created and before it is activated." |
| 35 | +virtualenvwrapper_make_hook "$WORKON_HOME/postmkvirtualenv" \ |
| 36 | + "This hook is run after a new virtualenv is activated." |
| 37 | +# rmvirtualenv |
| 38 | +virtualenvwrapper_make_hook "$WORKON_HOME/prermvirtualenv" \ |
| 39 | + "This hook is run before a virtualenv is deleted." |
| 40 | +virtualenvwrapper_make_hook "$WORKON_HOME/postrmvirtualenv" \ |
| 41 | + "This hook is run after a virtualenv is deleted." |
| 42 | +# deactivate |
| 43 | +virtualenvwrapper_make_hook "$WORKON_HOME/predeactivate" \ |
| 44 | + "This hook is run before every virtualenv is deactivated." |
| 45 | +virtualenvwrapper_make_hook "$WORKON_HOME/postdeactivate" \ |
| 46 | + "This hook is run after every virtualenv is deactivated." |
| 47 | +# activate |
| 48 | +virtualenvwrapper_make_hook "$WORKON_HOME/preactivate" \ |
| 49 | + "This hook is run before every virtualenv is activated." |
| 50 | +virtualenvwrapper_make_hook "$WORKON_HOME/postactivate" \ |
| 51 | + "This hook is run after every virtualenv is activated." |
0 commit comments