Skip to content

Commit ed16511

Browse files
Keep active folder in PATH when navigating project folders
1 parent a142f27 commit ed16511

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

shell_hook.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ TOOL_FOLDER=".luca"
3232

3333
# This function adds tool_bin_dir to PATH if it exists and isn't already there.
3434
# It is designed to be idempotent and prevent PATH duplication.
35+
# When navigating to subdirectories of a project, it keeps the project's tool path in PATH.
3536
update_path() {
3637
# Look for the active tools directory in the current location
3738
local tool_bin_dir="$(pwd)/$TOOL_FOLDER/active"
39+
local current_pwd="$(pwd)"
3840

39-
# Only proceed if the tool directory exists
41+
# Only proceed if the tool directory exists in the current directory
4042
if [ -d "$tool_bin_dir" ]; then
4143
# Check if tool_bin_dir is already in PATH to avoid duplicates
4244
case ":$PATH:" in
@@ -52,7 +54,8 @@ update_path() {
5254
;;
5355
esac
5456
else
55-
# If the directory doesn't exist, remove any stale tool entries from PATH
57+
# Current directory doesn't have .luca/active
58+
# Check if there are any .luca/active entries in PATH that should be cleaned up
5659
if [[ ":$PATH:" == *"/$TOOL_FOLDER/active:"* ]]; then
5760
local p
5861
local new_path=""
@@ -67,7 +70,17 @@ update_path() {
6770
current_path="${current_path#*:}"
6871
fi
6972

70-
if [[ "$p" != *"/$TOOL_FOLDER/active" ]]; then
73+
if [[ "$p" == *"/$TOOL_FOLDER/active" ]]; then
74+
# This is a tool directory entry - check if we should keep it
75+
# Get the project root (parent of .luca/active)
76+
local project_root="${p%/$TOOL_FOLDER/active}"
77+
# Keep this entry if current directory is the project root or a subdirectory of it
78+
if [[ "$current_pwd" == "$project_root" || "$current_pwd" == "$project_root/"* ]]; then
79+
new_path="${new_path:+$new_path:}$p"
80+
fi
81+
# Otherwise, skip this entry (effectively removing it from PATH)
82+
else
83+
# Not a tool directory, keep it in PATH
7184
new_path="${new_path:+$new_path:}$p"
7285
fi
7386
done
@@ -173,4 +186,4 @@ if [[ -n "$BASH_VERSION" && "${BASH_SOURCE[0]}" != "$0" ]] || [[ -n "$ZSH_VERSIO
173186

174187
# Update the PATH immediately for the current directory
175188
update_path
176-
fi
189+
fi

0 commit comments

Comments
 (0)