Skip to content

Commit d732c72

Browse files
committed
chore: wip
1 parent 12e3399 commit d732c72

File tree

1 file changed

+47
-25
lines changed

1 file changed

+47
-25
lines changed

packages/launchpad/src/dev/shellcode.ts

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ export function shellcode(_testMode: boolean = false): string {
2929

3030
return `
3131
# MINIMAL LAUNCHPAD SHELL INTEGRATION - DEBUGGING VERSION
32-
# This is a minimal version to isolate the hanging issue
33-
3432
# Exit early if shell integration is disabled or explicit test mode
3533
if [[ "$LAUNCHPAD_DISABLE_SHELL_INTEGRATION" == "1" || "$LAUNCHPAD_TEST_MODE" == "1" ]]; then
3634
return 0 2>/dev/null || exit 0
@@ -98,8 +96,6 @@ __launchpad_switch_environment() {
9896
fi
9997
export __LAUNCHPAD_LAST_VERBOSE_KEY="$__lp_verbose_key"
10098
101-
# Removed verbose shell integration start message
102-
10399
# Known dependency filenames (keep in sync with DEPENDENCY_FILE_NAMES in src/env.ts)
104100
local _dep_names=(
105101
# Launchpad-specific files (highest priority)
@@ -123,7 +119,7 @@ __launchpad_switch_environment() {
123119
# Version control files
124120
".nvmrc" ".node-version" ".ruby-version" ".python-version" ".terraform-version"
125121
# Package manager files
126-
"yarn.lock" "bun.lockb" ".yarnrc"
122+
"yarn.lock" "bun.lock" "bun.lockb" ".yarnrc"
127123
)
128124
129125
# Step 1: Find project directory using our fast binary (no artificial timeout)
@@ -151,21 +147,11 @@ __launchpad_switch_environment() {
151147
152148
# Removed verbose project detection message
153149
154-
# Step 2: Always ensure global paths are available (even in projects)
155-
# Use ~/.local/bin first, then launchpad global bin to ensure proper path priority
150+
# Step 2: Prepare global paths but don't add them yet
151+
# We'll add them after project-specific paths to ensure proper precedence
156152
local local_bin="$HOME/.local/bin"
157153
local global_bin="$HOME/.local/share/launchpad/global/bin"
158154
159-
# Add ~/.local/bin to PATH if not already there
160-
if [[ -d "$local_bin" && ":$PATH:" != *":$local_bin:"* ]]; then
161-
export PATH="$local_bin:$PATH"
162-
fi
163-
164-
# Add launchpad global bin to PATH if not already there
165-
if [[ -d "$global_bin" && ":$PATH:" != *":$global_bin:"* ]]; then
166-
export PATH="$global_bin:$PATH"
167-
fi
168-
169155
# Step 2.0: Detect global ready markers (persistent) to skip redundant global setup
170156
local ready_cache_marker="$HOME/.cache/launchpad/global_ready"
171157
local ready_global_marker="$HOME/.local/share/launchpad/global/.ready"
@@ -279,6 +265,18 @@ __launchpad_switch_environment() {
279265
unset LAUNCHPAD_ENV_BIN_PATH
280266
unset __LAUNCHPAD_LAST_ACTIVATION_KEY
281267
fi
268+
269+
# Ensure global paths are still available when not in a project
270+
# Add ~/.local/bin to PATH if not already there
271+
if [[ -d "$local_bin" && ":$PATH:" != *":$local_bin:"* ]]; then
272+
export PATH="$local_bin:$PATH"
273+
fi
274+
275+
# Add launchpad global bin to PATH if not already there
276+
if [[ -d "$global_bin" && ":$PATH:" != *":$global_bin:"* ]]; then
277+
export PATH="$global_bin:$PATH"
278+
fi
279+
282280
return 0
283281
fi
284282
@@ -335,7 +333,23 @@ __launchpad_switch_environment() {
335333
if [[ -d "$env_dir/bin" ]]; then
336334
export LAUNCHPAD_CURRENT_PROJECT="$project_dir"
337335
export LAUNCHPAD_ENV_BIN_PATH="$env_dir/bin"
336+
337+
# Remove project-specific path if it was already in PATH
338+
export PATH=$(echo "$PATH" | sed "s|$env_dir/bin:||g" | sed "s|:$env_dir/bin||g" | sed "s|^$env_dir/bin$||g")
339+
340+
# Add project-specific path first (highest priority)
338341
export PATH="$env_dir/bin:$PATH"
342+
343+
# Now ensure global paths are available but with lower priority
344+
# Add ~/.local/bin to PATH if not already there (after project paths)
345+
if [[ -d "$local_bin" && ":$PATH:" != *":$local_bin:"* ]]; then
346+
export PATH="$PATH:$local_bin"
347+
fi
348+
349+
# Add launchpad global bin to PATH if not already there (after project and ~/.local/bin)
350+
if [[ -d "$global_bin" && ":$PATH:" != *":$global_bin:"* ]]; then
351+
export PATH="$PATH:$global_bin"
352+
fi
339353
# Removed verbose activated environment path message
340354
# Ensure dynamic linker can find Launchpad-managed libraries (macOS/Linux)
341355
# Build a list of library directories from the active environment and global install
@@ -387,8 +401,16 @@ __launchpad_switch_environment() {
387401
fi
388402
done
389403
else
390-
# Environment not ready - user can run 'launchpad install <project>' manually when needed
391-
:
404+
# Environment not ready - still ensure global paths are available
405+
# Add ~/.local/bin to PATH if not already there
406+
if [[ -d "$local_bin" && ":$PATH:" != *":$local_bin:"* ]]; then
407+
export PATH="$local_bin:$PATH"
408+
fi
409+
410+
# Add launchpad global bin to PATH if not already there
411+
if [[ -d "$global_bin" && ":$PATH:" != *":$global_bin:"* ]]; then
412+
export PATH="$global_bin:$PATH"
413+
fi
392414
fi
393415
fi
394416
@@ -417,14 +439,14 @@ if [[ -n "$ZSH_VERSION" ]]; then
417439
return 0
418440
fi
419441
export __LAUNCHPAD_IN_HOOK=1
420-
442+
421443
# Only run the environment switching logic, not the full shell integration
422444
__launchpad_switch_environment
423-
445+
424446
# Clean up hook flag explicitly
425447
unset __LAUNCHPAD_IN_HOOK 2>/dev/null || true
426448
}
427-
449+
428450
# Ensure hook arrays exist
429451
if ! typeset -p chpwd_functions >/dev/null 2>&1; then
430452
typeset -ga chpwd_functions
@@ -441,14 +463,14 @@ elif [[ -n "$BASH_VERSION" ]]; then
441463
return 0
442464
fi
443465
export __LAUNCHPAD_IN_HOOK=1
444-
466+
445467
# Only run the environment switching logic, not the full shell integration
446468
__launchpad_switch_environment
447-
469+
448470
# Clean up hook flag explicitly
449471
unset __LAUNCHPAD_IN_HOOK 2>/dev/null || true
450472
}
451-
473+
452474
# Add to PROMPT_COMMAND if not already there
453475
if [[ "$PROMPT_COMMAND" != *"__launchpad_prompt_command"* ]]; then
454476
PROMPT_COMMAND="__launchpad_prompt_command;\$PROMPT_COMMAND"

0 commit comments

Comments
 (0)