4ed0bacbc7b1275b8dfa03de57d5f3ae601fbcd7

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

Message

Switch to default virtualenv if security check fails

Diff

 1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
 2index 424e6d3881f132d6b59c07d6a70d089c90f69779..c80015bfdb8a2aa866a404f787a2f03e9250be88 100644
 3--- a/autoswitch_virtualenv.plugin.zsh
 4+++ b/autoswitch_virtualenv.plugin.zsh
 5@@ -23,15 +23,22 @@ function check_venv()
 6 {
 7     if [ "$PWD" != "$MYOLDPWD" ]; then
 8         MYOLDPWD="$PWD"
 9+
10+        SWITCH_TO=""
11+
12         if [[ -f ".venv" ]]; then
13-          if [[ "$(stat -c %u .venv)" = "$(id -u)" ]]; then
14-            maybeworkon "$(cat .venv)"
15-            AUTOSWITCH_PROJECT="$PWD"
16-          else
17+          if [[ "$(stat -c %u .venv)" != "$(id -u)" ]]; then
18             echo "AUTOSWITCH WARNING: Found a .venv file but it is not owned by the current user"
19             echo "This will not be activated to prevent potentially malicious actions"
20             echo "Change ownership of .venv to '$USER' to fix this"
21+          else
22+            SWITCH_TO="$(cat .venv)"
23+            AUTOSWITCH_PROJECT="$PWD"
24           fi
25+        fi
26+
27+        if [[ -n "$SWITCH_TO" ]]; then
28+          maybeworkon "$SWITCH_TO"
29         elif [[ "$PWD" != "$AUTOSWITCH_PROJECT/"* ]]; then
30           default_venv
31           AUTOSWITCH_PROJECT=""