Skip to main content

Deactivate a venv if it stops existing

ID
35beaa6
date
2024-03-30 18:05:12+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
45b10d5
message
Deactivate a venv if it stops existing
changed files
1 file, 10 additions, 1 deletion

Changed files

fish_functions/fish_prompt.fish (4684) → fish_functions/fish_prompt.fish (4953)

diff --git a/fish_functions/fish_prompt.fish b/fish_functions/fish_prompt.fish
index e0a5f7d..59f9f04 100644
--- a/fish_functions/fish_prompt.fish
+++ b/fish_functions/fish_prompt.fish
@@ -54,7 +54,16 @@ end
 set -x VIRTUAL_ENV_DISABLE_PROMPT 1
 
 function print_venv_information
-    if [ -n "$VIRTUAL_ENV" ]
+    if test -n "$VIRTUAL_ENV"
+
+        # If the virtualenv has ceased to exist since the last prompt,
+        # then it can't possibly be activated, so deactivate and don't
+        # print it in the prompt.
+        if test ! -d "$VIRTUAL_ENV"
+            deactivate
+            return
+        end
+
         set_color normal
         printf " using "