Skip to content
This repository was archived by the owner on Sep 25, 2025. It is now read-only.

Commit b8350bd

Browse files
authored
Improve initialization (#2)
* Improve initialization * Force initialization during startup * Rename to autovenv.fish
1 parent 3f1504a commit b8350bd

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

conf.d/autoenv.fish renamed to conf.d/autovenv.fish

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function applyAutoenv
3838
set _tree (dirname $_tree)
3939
end
4040
# If we're *not* in an active venv and the venv source dir exists we activate it and return.
41-
if test -z "$VIRTUAL_ENV" -a -e "$_source"
41+
if test \( -z "$VIRTUAL_ENV" -o "$_autovenv_initialized" = "0" \) -a -e "$_source"
4242
source "$_source"
4343
if test "$autovenv_announce" = "yes"
4444
echo "Activated Virtual Environment ($__autovenv_new)"
@@ -66,13 +66,17 @@ function applyAutoenv
6666
end
6767
end
6868

69-
# We need to run AutoVenv on the initialization of each session.
70-
if status is-interactive
69+
# Activates AutoVenv based on directory changes.
70+
function autovenv --on-variable PWD -d "Automatic activation of Python virtual environments"
7171
applyAutoenv
7272
end
7373

74-
## AutoVenv Function.
75-
# Activates on directory changes.
76-
function autovenv --on-variable PWD -d "Automatic activation of Python virtual environments"
77-
applyAutoenv
74+
set --global _autovenv_initialized 0
75+
76+
# Activates AutoVenv on initialization of the session after sourcing config.fish.
77+
function __autovenv_on_prompt --on-event fish_prompt
78+
if test "$_autovenv_initialized" = "0"
79+
applyAutoenv
80+
set --global _autovenv_initialized 1
81+
end
7882
end

0 commit comments

Comments
 (0)