@@ -162,6 +162,32 @@ __launchpad_update_path() {
162
162
fi
163
163
}
164
164
165
+ # Ensure the active environment's bin path stays first in PATH
166
+ __launchpad_ensure_env_path_priority() {
167
+ if [[ -n "$LAUNCHPAD_ENV_BIN_PATH" && -d "$LAUNCHPAD_ENV_BIN_PATH" ]]; then
168
+ local OLD_IFS="$IFS"
169
+ local rebuilt_path=""
170
+ IFS=':'
171
+ for seg in $PATH; do
172
+ if [[ -z "$seg" ]]; then continue; fi
173
+ if [[ "$seg" == "$LAUNCHPAD_ENV_BIN_PATH" ]]; then continue; fi
174
+ if [[ -z "$rebuilt_path" ]]; then
175
+ rebuilt_path="$seg"
176
+ else
177
+ rebuilt_path="$rebuilt_path:$seg"
178
+ fi
179
+ done
180
+ IFS="$OLD_IFS"
181
+ if [[ -n "$rebuilt_path" ]]; then
182
+ export PATH="$LAUNCHPAD_ENV_BIN_PATH:$rebuilt_path"
183
+ else
184
+ export PATH="$LAUNCHPAD_ENV_BIN_PATH"
185
+ fi
186
+ # Refresh command hash tables for both bash and zsh
187
+ hash -r 2>/dev/null || rehash 2>/dev/null || true
188
+ fi
189
+ }
190
+
165
191
# Fast library path update for quick activation (no expensive find operations)
166
192
__launchpad_update_library_paths_fast() {
167
193
local env_dir="$1"
@@ -793,10 +819,11 @@ __launchpad_chpwd() {
793
819
if [[ -n "$__lp_cache_ok" ]]; then
794
820
# Instant activation from persistent cache (no filesystem scans)
795
821
export PATH="$env_dir/bin:$LAUNCHPAD_ORIGINAL_PATH"
822
+ export LAUNCHPAD_ENV_BIN_PATH="$env_dir/bin"
796
823
__launchpad_update_library_paths_fast "$env_dir"
797
824
__launchpad_ensure_global_path_fast
798
825
__launchpad_ensure_system_path
799
- hash -r 2>/dev/null || true
826
+ __launchpad_ensure_env_path_priority
800
827
# Verbose diagnostics for fast cached activation
801
828
if [[ "$LAUNCHPAD_VERBOSE" == "true" ]]; then
802
829
printf "🔍 Fast path (cache): env_dir=%s ready=%s\n" "$env_dir" "$([ -f "$env_dir/.launchpad_ready" ] && echo true || echo false)" >&2
@@ -820,10 +847,11 @@ __launchpad_chpwd() {
820
847
# use glob expansion which is faster than ls
821
848
if [[ -d "$env_dir/bin" ]] && [[ $__lp_markers_ready -eq 1 || $(echo "$env_dir/bin"/*) != "$env_dir/bin/*" ]]; then
822
849
export PATH="$env_dir/bin:$LAUNCHPAD_ORIGINAL_PATH"
850
+ export LAUNCHPAD_ENV_BIN_PATH="$env_dir/bin"
823
851
__launchpad_update_library_paths_fast "$env_dir"
824
852
__launchpad_ensure_global_path_fast
825
853
__launchpad_ensure_system_path
826
- hash -r 2>/dev/null || true
854
+ __launchpad_ensure_env_path_priority
827
855
828
856
# Update persistent cache for instant future activation and keep parity with dep file
829
857
mkdir -p "$(dirname "$cache_file")" 2>/dev/null || true
@@ -906,9 +934,8 @@ __launchpad_chpwd() {
906
934
# Ensure global dependencies are still in PATH after project setup
907
935
__launchpad_ensure_global_path
908
936
__launchpad_ensure_system_path
909
-
910
- # Clear command hash table to ensure commands are found in new PATH
911
- hash -r 2>/dev/null || true
937
+ export LAUNCHPAD_ENV_BIN_PATH="$env_dir/bin"
938
+ __launchpad_ensure_env_path_priority
912
939
913
940
# Mark environment ready for instant future activation (both cache and marker)
914
941
mkdir -p "$env_dir" 2>/dev/null || true
@@ -927,7 +954,8 @@ __launchpad_chpwd() {
927
954
__launchpad_update_library_paths "$env_dir"
928
955
__launchpad_ensure_global_path
929
956
__launchpad_ensure_system_path
930
- hash -r 2>/dev/null || true
957
+ export LAUNCHPAD_ENV_BIN_PATH="$env_dir/bin"
958
+ __launchpad_ensure_env_path_priority
931
959
932
960
printf "${ activationMessage } \n" >&2
933
961
else
@@ -1090,6 +1118,8 @@ __launchpad_auto_refresh_check() {
1090
1118
__launchpad_refresh_global_paths
1091
1119
__launchpad_source_hooks_dir "$HOME/.config/launchpad/hooks/post-refresh.d"
1092
1120
fi
1121
+ # Always reassert env path precedence on each prompt
1122
+ __launchpad_ensure_env_path_priority
1093
1123
}
1094
1124
1095
1125
# Check for global refresh on every prompt (lightweight check)
0 commit comments