49d0c2c8ffc36a942940fbf030cf7609f465cd13

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

Message

Merge pull request #156 from MichaelAquilina/fix/check_venv_startup

Fix issue where virtualenv was not loaded correctly

Diff

 1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
 2index 87123c13bd525a507d59daa5edc8325ac85a54a8..6b9811a3ed90cfe4349d4c2a8bb5d3af260b96f1 100644
 3--- a/autoswitch_virtualenv.plugin.zsh
 4+++ b/autoswitch_virtualenv.plugin.zsh
 5@@ -390,6 +390,15 @@ function disable_autoswitch_virtualenv() {
 6     add-zsh-hook -D chpwd check_venv
 7 }
 8 
 9+# This function is only used to startup zsh-autoswitch-virtualenv
10+# the first time a terminal is started up
11+# it waits for the terminal to be ready using precmd and then
12+# imediately removes itself from the zsh-hook
13+function _autoswitch_startup() {
14+    add-zsh-hook -D precmd _startup
15+    check_venv
16+}
17+
18 
19 enable_autoswitch_virtualenv
20-check_venv
21+add-zsh-hook precmd _autoswitch_startup
22diff --git a/tests/test_plugin.zunit b/tests/test_plugin.zunit
23index 5a2f2e96c32e76279bff3321a0925a1dea5f1f1c..eeb2c5fe46f9111caa61d9762f296afcad97aead 100644
24--- a/tests/test_plugin.zunit
25+++ b/tests/test_plugin.zunit
26@@ -24,23 +24,6 @@
27 }
28 
29 
30-@test 'plugin - does nothing on load if no default set' {
31-    unset AUTOSWITCH_DEFAULTENV
32-
33-    run load ../autoswitch_virtualenv.plugin.zsh
34-
35-    assert $status equals 0
36-    assert "$output" is_empty
37-}
38-
39-@test 'plugin - runs default env on load' {
40-    AUTOSWITCH_DEFAULTENV="foobar"
41-    run load ../autoswitch_virtualenv.plugin.zsh
42-
43-    assert $status equals 0
44-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[🐍$PYTHON_VERSION]\e[0m"
45-}
46-
47 @test 'plugin - does nothing if switching to directory without .venv' {
48     unset AUTOSWITCH_DEFAULTENV
49     load ../autoswitch_virtualenv.plugin.zsh