|
44 | 44 | # 11. The virtual environment is activated. |
45 | 45 | # |
46 | 46 |
|
47 | | -# Make sure there is a default value for WORKON_HOME. |
48 | | -# You can override this setting in your .bashrc. |
49 | | -if [ "$WORKON_HOME" = "" ] |
50 | | -then |
51 | | - export WORKON_HOME="$HOME/.virtualenvs" |
52 | | -fi |
53 | | - |
54 | 47 | # Locate the global Python where virtualenvwrapper is installed. |
55 | 48 | if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] |
56 | 49 | then |
57 | 50 | VIRTUALENVWRAPPER_PYTHON="$(\which python)" |
58 | 51 | fi |
59 | 52 |
|
60 | | -# If the path is relative, prefix it with $HOME |
61 | | -# (note: for compatibility) |
62 | | -if echo "$WORKON_HOME" | (unset GREP_OPTIONS; grep -e '^[^/~]' > /dev/null) |
63 | | -then |
64 | | - export WORKON_HOME="$HOME/$WORKON_HOME" |
65 | | -fi |
| 53 | +virtualenvwrapper_derive_workon_home() { |
| 54 | + typeset workon_home_dir="$WORKON_HOME" |
66 | 55 |
|
67 | | -# Only call on Python to fix the path if it looks like the |
68 | | -# path might contain stuff to expand. |
69 | | -# (it might be possible to do this in shell, but I don't know a |
70 | | -# cross-shell-safe way of doing it -wolever) |
71 | | -if echo "$WORKON_HOME" | (unset GREP_OPTIONS; egrep -e "([\$~]|//)" >/dev/null) |
72 | | -then |
73 | | - # This will normalize the path by: |
74 | | - # - Removing extra slashes (e.g., when TMPDIR ends in a slash) |
75 | | - # - Expanding variables (e.g., $foo) |
76 | | - # - Converting ~s to complete paths (e.g., ~/ to /home/brian/ and ~arthur to /home/arthur) |
77 | | - WORKON_HOME=$("$VIRTUALENVWRAPPER_PYTHON" -c "import os; print os.path.expandvars(os.path.expanduser(\"$WORKON_HOME\"))") |
78 | | - export WORKON_HOME |
79 | | -fi |
| 56 | + # Make sure there is a default value for WORKON_HOME. |
| 57 | + # You can override this setting in your .bashrc. |
| 58 | + if [ "$workon_home_dir" = "" ] |
| 59 | + then |
| 60 | + workon_home_dir="$HOME/.virtualenvs" |
| 61 | + fi |
| 62 | + |
| 63 | + # If the path is relative, prefix it with $HOME |
| 64 | + # (note: for compatibility) |
| 65 | + if echo "$workon_home_dir" | (unset GREP_OPTIONS; grep -e '^[^/~]' > /dev/null) |
| 66 | + then |
| 67 | + workon_home_dir="$HOME/$WORKON_HOME" |
| 68 | + fi |
| 69 | + |
| 70 | + # Only call on Python to fix the path if it looks like the |
| 71 | + # path might contain stuff to expand. |
| 72 | + # (it might be possible to do this in shell, but I don't know a |
| 73 | + # cross-shell-safe way of doing it -wolever) |
| 74 | + if echo "$workon_home_dir" | (unset GREP_OPTIONS; egrep -e "([\$~]|//)" >/dev/null) |
| 75 | + then |
| 76 | + # This will normalize the path by: |
| 77 | + # - Removing extra slashes (e.g., when TMPDIR ends in a slash) |
| 78 | + # - Expanding variables (e.g., $foo) |
| 79 | + # - Converting ~s to complete paths (e.g., ~/ to /home/brian/ and ~arthur to /home/arthur) |
| 80 | + workon_home_dir=$("$VIRTUALENVWRAPPER_PYTHON" -c "import os; print os.path.expandvars(os.path.expanduser(\"$workon_home_dir\"))") |
| 81 | + fi |
| 82 | + |
| 83 | + echo "$workon_home_dir" |
| 84 | + return 0 |
| 85 | +} |
80 | 86 |
|
81 | 87 | # Verify that the WORKON_HOME directory exists |
82 | 88 | virtualenvwrapper_verify_workon_home () { |
@@ -131,6 +137,7 @@ virtualenvwrapper_run_hook () { |
131 | 137 |
|
132 | 138 | # Set up virtualenvwrapper properly |
133 | 139 | virtualenvwrapper_initialize () { |
| 140 | + export WORKON_HOME=$(virtualenvwrapper_derive_workon_home) |
134 | 141 | virtualenvwrapper_verify_workon_home -q || return 1 |
135 | 142 | virtualenvwrapper_run_hook "initialize" |
136 | 143 | if [ $? -ne 0 ] |
|
0 commit comments