@@ -54,20 +54,31 @@ export PATH="${TMP}/pyenv/plugins/pyenv-virtualenv/shims:\${PATH}";
5454export PYENV_VIRTUALENV_INIT=1;
5555_pyenv_virtualenv_hook() {
5656 local ret=\$ ?
57- local pvh_local=""
58- if [ -f "\$ {PWD}/.python-version" ]; then
59- pvh_local=\$ (< "\$ {PWD}/.python-version") 2>/dev/null || true
60- fi
61- local pvh_global=""
62- if [ -f "\$ {PYENV_ROOT}/version" ]; then
63- pvh_global=\$ (< "\$ {PYENV_ROOT}/version") 2>/dev/null || true
64- fi
6557 if [ "\$ {PWD}" = "\$ {_PYENV_VH_PWD-}" ] \\
6658 && [ "\$ {PYENV_VERSION-}" = "\$ {_PYENV_VH_VERSION-}" ] \\
67- && [ "\$ {pvh_local}" = "\$ {_PYENV_VH_LOCAL-}" ] \\
68- && [ "\$ {pvh_global}" = "\$ {_PYENV_VH_GLOBAL-}" ] \\
69- && [ "\$ {VIRTUAL_ENV-}" = "\$ {_PYENV_VH_VENV-}" ]; then
70- return \$ ret
59+ && [ "\$ {VIRTUAL_ENV-}" = "\$ {_PYENV_VH_VENV-}" ] \\
60+ && [ -f "\$ {_PYENV_VH_MARKER-}" ]; then
61+ if [ -n "\$ {PYENV_VERSION-}" ]; then
62+ return \$ ret
63+ fi
64+ local _pvh_d="\$ {PWD}" _pvh_stale=0 _pvh_found=0
65+ while :; do
66+ if [ -f "\$ {_pvh_d}/.python-version" ]; then
67+ _pvh_found=1
68+ [ "\$ {_pvh_d}/.python-version" -nt "\$ {_PYENV_VH_MARKER}" ] && _pvh_stale=1
69+ break
70+ fi
71+ [ "\$ {_pvh_d}" -nt "\$ {_PYENV_VH_MARKER}" ] && { _pvh_stale=1; break; }
72+ [ "\$ {_pvh_d}" = "/" ] && break
73+ _pvh_d="\$ {_pvh_d%/*}"
74+ [ -z "\$ {_pvh_d}" ] && _pvh_d="/"
75+ done
76+ if [ "\$ {_pvh_stale}" = 0 ] && [ "\$ {_pvh_found}" = 0 ]; then
77+ [ -f "\$ {PYENV_ROOT}/version" ] \\
78+ && [ "\$ {PYENV_ROOT}/version" -nt "\$ {_PYENV_VH_MARKER}" ] \\
79+ && _pvh_stale=1
80+ fi
81+ [ "\$ {_pvh_stale}" = 0 ] && return \$ ret
7182 fi
7283 if [ -n "\$ {VIRTUAL_ENV-}" ]; then
7384 eval "\$ (pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true
@@ -76,9 +87,9 @@ _pyenv_virtualenv_hook() {
7687 fi
7788 _PYENV_VH_PWD="\$ {PWD}"
7889 _PYENV_VH_VERSION="\$ {PYENV_VERSION-}"
79- _PYENV_VH_LOCAL="\$ {pvh_local}"
80- _PYENV_VH_GLOBAL="\$ {pvh_global}"
8190 _PYENV_VH_VENV="\$ {VIRTUAL_ENV-}"
91+ _PYENV_VH_MARKER="\$ {PYENV_ROOT}/.pyenv-vh-marker-\$\$ "
92+ : > "\$ {_PYENV_VH_MARKER}"
8293 return \$ ret
8394};
8495if ! [[ "\$ {PROMPT_COMMAND-}" =~ _pyenv_virtualenv_hook ]]; then
@@ -98,20 +109,31 @@ set -gx PATH '${TMP}/pyenv/plugins/pyenv-virtualenv/shims' \$PATH;
98109set -gx PYENV_VIRTUALENV_INIT 1;
99110function _pyenv_virtualenv_hook --on-event fish_prompt;
100111 set -l ret \$ status
101- set -l pvh_local ""
102- if test -f "\$ PWD/.python-version"
103- read -z pvh_local < "\$ PWD/.python-version" 2>/dev/null; or true
104- end
105- set -l pvh_global ""
106- if test -f "\$ PYENV_ROOT/version"
107- read -z pvh_global < "\$ PYENV_ROOT/version" 2>/dev/null; or true
108- end
109112 if test "\$ PWD" = "\$ _PYENV_VH_PWD" \\
110113 -a "\$ PYENV_VERSION" = "\$ _PYENV_VH_VERSION" \\
111- -a "\$ pvh_local" = "\$ _PYENV_VH_LOCAL" \\
112- -a "\$ pvh_global" = "\$ _PYENV_VH_GLOBAL" \\
113- -a "\$ VIRTUAL_ENV" = "\$ _PYENV_VH_VENV"
114- return \$ ret
114+ -a "\$ VIRTUAL_ENV" = "\$ _PYENV_VH_VENV" \\
115+ -a -f "\$ _PYENV_VH_MARKER"
116+ if test -n "\$ PYENV_VERSION"
117+ return \$ ret
118+ end
119+ set -l d "\$ PWD"
120+ set -l stale 0
121+ set -l found 0
122+ while true
123+ if test -f "\$ d/.python-version"
124+ set found 1
125+ test "\$ d/.python-version" -nt "\$ _PYENV_VH_MARKER"; and set stale 1
126+ break
127+ end
128+ test "\$ d" -nt "\$ _PYENV_VH_MARKER"; and begin; set stale 1; break; end
129+ test "\$ d" = "/"; and break
130+ set d (string replace -r '/[^/]*\$ ' '' -- "\$ d")
131+ test -z "\$ d"; and set d "/"
132+ end
133+ if test \$ stale = 0 -a \$ found = 0
134+ test -f "\$ PYENV_ROOT/version"; and test "\$ PYENV_ROOT/version" -nt "\$ _PYENV_VH_MARKER"; and set stale 1
135+ end
136+ test \$ stale = 0; and return \$ ret
115137 end
116138 if [ -n "\$ VIRTUAL_ENV" ]
117139 pyenv activate --quiet; or pyenv deactivate --quiet; or true
@@ -120,9 +142,9 @@ function _pyenv_virtualenv_hook --on-event fish_prompt;
120142 end
121143 set -g _PYENV_VH_PWD "\$ PWD"
122144 set -g _PYENV_VH_VERSION "\$ PYENV_VERSION"
123- set -g _PYENV_VH_LOCAL "\$ pvh_local"
124- set -g _PYENV_VH_GLOBAL "\$ pvh_global"
125145 set -g _PYENV_VH_VENV "\$ VIRTUAL_ENV"
146+ set -g _PYENV_VH_MARKER "\$ PYENV_ROOT/.pyenv-vh-marker-\$ fish_pid"
147+ command touch "\$ _PYENV_VH_MARKER"
126148 return \$ ret
127149end
128150EOS
@@ -137,20 +159,31 @@ export PATH="${TMP}/pyenv/plugins/pyenv-virtualenv/shims:\${PATH}";
137159export PYENV_VIRTUALENV_INIT=1;
138160_pyenv_virtualenv_hook() {
139161 local ret=\$ ?
140- local pvh_local=""
141- if [ -f "\$ {PWD}/.python-version" ]; then
142- pvh_local=\$ (< "\$ {PWD}/.python-version") 2>/dev/null || true
143- fi
144- local pvh_global=""
145- if [ -f "\$ {PYENV_ROOT}/version" ]; then
146- pvh_global=\$ (< "\$ {PYENV_ROOT}/version") 2>/dev/null || true
147- fi
148162 if [ "\$ {PWD}" = "\$ {_PYENV_VH_PWD-}" ] \\
149163 && [ "\$ {PYENV_VERSION-}" = "\$ {_PYENV_VH_VERSION-}" ] \\
150- && [ "\$ {pvh_local}" = "\$ {_PYENV_VH_LOCAL-}" ] \\
151- && [ "\$ {pvh_global}" = "\$ {_PYENV_VH_GLOBAL-}" ] \\
152- && [ "\$ {VIRTUAL_ENV-}" = "\$ {_PYENV_VH_VENV-}" ]; then
153- return \$ ret
164+ && [ "\$ {VIRTUAL_ENV-}" = "\$ {_PYENV_VH_VENV-}" ] \\
165+ && [ -f "\$ {_PYENV_VH_MARKER-}" ]; then
166+ if [ -n "\$ {PYENV_VERSION-}" ]; then
167+ return \$ ret
168+ fi
169+ local _pvh_d="\$ {PWD}" _pvh_stale=0 _pvh_found=0
170+ while :; do
171+ if [ -f "\$ {_pvh_d}/.python-version" ]; then
172+ _pvh_found=1
173+ [ "\$ {_pvh_d}/.python-version" -nt "\$ {_PYENV_VH_MARKER}" ] && _pvh_stale=1
174+ break
175+ fi
176+ [ "\$ {_pvh_d}" -nt "\$ {_PYENV_VH_MARKER}" ] && { _pvh_stale=1; break; }
177+ [ "\$ {_pvh_d}" = "/" ] && break
178+ _pvh_d="\$ {_pvh_d%/*}"
179+ [ -z "\$ {_pvh_d}" ] && _pvh_d="/"
180+ done
181+ if [ "\$ {_pvh_stale}" = 0 ] && [ "\$ {_pvh_found}" = 0 ]; then
182+ [ -f "\$ {PYENV_ROOT}/version" ] \\
183+ && [ "\$ {PYENV_ROOT}/version" -nt "\$ {_PYENV_VH_MARKER}" ] \\
184+ && _pvh_stale=1
185+ fi
186+ [ "\$ {_pvh_stale}" = 0 ] && return \$ ret
154187 fi
155188 if [ -n "\$ {VIRTUAL_ENV-}" ]; then
156189 eval "\$ (pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true
@@ -159,9 +192,9 @@ _pyenv_virtualenv_hook() {
159192 fi
160193 _PYENV_VH_PWD="\$ {PWD}"
161194 _PYENV_VH_VERSION="\$ {PYENV_VERSION-}"
162- _PYENV_VH_LOCAL="\$ {pvh_local}"
163- _PYENV_VH_GLOBAL="\$ {pvh_global}"
164195 _PYENV_VH_VENV="\$ {VIRTUAL_ENV-}"
196+ _PYENV_VH_MARKER="\$ {PYENV_ROOT}/.pyenv-vh-marker-\$\$ "
197+ : > "\$ {_PYENV_VH_MARKER}"
165198 return \$ ret
166199};
167200typeset -g -a precmd_functions
0 commit comments