448215e25f9faf8b396bf9723cef8277ee751353

Author
Michael Aquilina <michaelaquilina@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

Merge pull request #4 from MichaelAquilina/dont_deactivate_on_subdirectories

Dont deactivate a virtualenv if its a subdirectory of a project

Diff

 1diff --git a/README.md b/README.md
 2index a9f58b76f4ac3a4976f6cb0d5cdc973c6a27c507..3785c103ba7b95e7a8add791b4585f0078b8b7ac 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -117,6 +117,19 @@ $
 6 Otherwise, `deactivate` will simply be called on the virtualenv to switch back to the global
 7 python environment.
 8 
 9+Autoswitching is smart enough to detect that you have traversed to a project subdirectory. So your
10+virtualenv will not be deactivated if you enter a subdirectory.
11+
12+```
13+$ cd my-python-project
14+Switching virtualenv: my-python-project  [Python 3.4.3+]
15+$ cd src
16+$ # Notice how this has not deactivated the project virtualenv
17+$ cd ../..
18+Switching virtualenv: mydefaultenv  [Python 3.4.3+]
19+$ # exited the project parent folder, so the virtualenv is now deactivated
20+```
21+
22 You can remove the virtual environment for a directory you are currently in using the `rmvenv`
23 helper function:
24 
25diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
26index effa6d695163b61af167bdaaa19dfe8b45cd9108..52760adeccafb14b0b092cf363fbf3e80ef6b1b4 100644
27--- a/autoswitch_virtualenv.plugin.zsh
28+++ b/autoswitch_virtualenv.plugin.zsh
29@@ -24,8 +24,10 @@ function check_venv()
30         MYOLDPWD="$PWD"
31         if [[ -f ".venv" ]]; then
32           maybeworkon "$(cat .venv)"
33-        else
34+          AUTOSWITCH_PROJECT="$PWD"
35+        elif [[ "$PWD" != "$AUTOSWITCH_PROJECT/"* ]]; then
36           default_venv
37+          AUTOSWITCH_PROJECT=""
38         fi
39     fi
40 }