@@ -30,6 +30,12 @@ if [[ "$LAUNCHPAD_DISABLE_SHELL_INTEGRATION" == "1"${testModeCheck} ]]; then
30
30
return 0 2>/dev/null || exit 0
31
31
fi
32
32
33
+ # Skip shell integration during initial shell startup to avoid interfering with prompt initialization
34
+ # This prevents conflicts with starship and other prompt systems during .zshrc loading
35
+ if [[ "$LAUNCHPAD_SKIP_INITIAL_INTEGRATION" == "1" ]]; then
36
+ return 0 2>/dev/null || exit 0
37
+ fi
38
+
33
39
# Set up directory change hooks for zsh and bash (do this first, before any processing guards)
34
40
if [[ -n "$ZSH_VERSION" ]]; then
35
41
# zsh hook
79
85
80
86
# Environment switching function (called by hooks)
81
87
__launchpad_switch_environment() {
88
+ # Start timer for performance tracking
89
+ local start_time=$(date +%s%3N 2>/dev/null || echo "0")
90
+
91
+ # Check if verbose mode is enabled
92
+ local verbose_mode="${ verboseDefault } "
93
+ if [[ -n "$LAUNCHPAD_VERBOSE" ]]; then
94
+ verbose_mode="$LAUNCHPAD_VERBOSE"
95
+ fi
96
+
97
+ if [[ "$verbose_mode" == "true" ]]; then
98
+ printf "⏱️ [0ms] Shell integration started for PWD=%s\\n" "$PWD" >&2
99
+ fi
100
+
82
101
# Step 1: Find project directory using our fast binary (with timeout)
83
102
local project_dir=""
84
- if timeout 0.5s ${ launchpadBinary } dev:find-project-root "$PWD" 2 >/dev/null; then
103
+ if timeout 0.5s ${ launchpadBinary } dev:find-project-root "$PWD" >/dev/null 2>&1 ; then
85
104
project_dir=$(LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 timeout 0.5s ${ launchpadBinary } dev:find-project-root "$PWD" 2>/dev/null || echo "")
86
105
fi
87
106
@@ -91,6 +110,39 @@ __launchpad_switch_environment() {
91
110
export PATH="$global_bin:$PATH"
92
111
fi
93
112
113
+ # Step 2.1: Check for global refresh marker and initialize newly available tools
114
+ local refresh_marker="$HOME/.cache/launchpad/shell_cache/global_refresh_needed"
115
+ if [[ -f "$refresh_marker" ]]; then
116
+ # Remove the marker file
117
+ rm -f "$refresh_marker" 2>/dev/null || true
118
+
119
+ # Re-initialize tools that may have just become available
120
+ # This mirrors the conditional checks typically found in shell configs
121
+
122
+ # Skip starship initialization - let user's shell config handle it
123
+ # This prevents conflicts with user's own starship configuration
124
+ # if command -v starship >/dev/null 2>&1 && [[ -z "$STARSHIP_SHELL" ]]; then
125
+ # if [[ -n "$ZSH_VERSION" ]]; then
126
+ # eval "$(starship init zsh 2>/dev/null || true)"
127
+ # elif [[ -n "$BASH_VERSION" ]]; then
128
+ # eval "$(starship init bash 2>/dev/null || true)"
129
+ # fi
130
+ # fi
131
+
132
+ # Refresh command hash table to pick up new binaries
133
+ hash -r 2>/dev/null || true
134
+
135
+ # Rehash for zsh to pick up new commands
136
+ if [[ -n "$ZSH_VERSION" ]]; then
137
+ rehash 2>/dev/null || true
138
+ fi
139
+
140
+ # Show refresh message if verbose
141
+ if [[ "$verbose_mode" == "true" ]]; then
142
+ printf "🔄 Shell environment refreshed for newly installed tools\\n" >&2
143
+ fi
144
+ fi
145
+
94
146
# If no project found, check if we need to deactivate current project
95
147
if [[ -z "$project_dir" ]]; then
96
148
# If we were in a project but now we're not, deactivate it
@@ -149,7 +201,7 @@ __launchpad_switch_environment() {
149
201
# If environment exists, activate it
150
202
if [[ -d "$env_dir/bin" ]]; then
151
203
export LAUNCHPAD_CURRENT_PROJECT="$project_dir"
152
- export LAUNCHPAD_ENV_BIN_PATH="$env_dir/bin"
204
+ export LAUNCHPAD_ENV_BIN_PATH="$env_dir/bin"
153
205
export PATH="$env_dir/bin:$PATH"
154
206
155
207
# Show activation message if enabled
@@ -161,7 +213,7 @@ __launchpad_switch_environment() {
161
213
# Use LAUNCHPAD_SHELL_INTEGRATION=1 to enable proper progress display
162
214
if LAUNCHPAD_DISABLE_SHELL_INTEGRATION=1 LAUNCHPAD_SHELL_INTEGRATION=1 timeout 30s ${ launchpadBinary } install "$project_dir"; then
163
215
# If install succeeded, try to activate the environment
164
- if [[ -d "$env_dir/bin" ]]; then
216
+ if [[ -d "$env_dir/bin" ]]; then
165
217
export LAUNCHPAD_CURRENT_PROJECT="$project_dir"
166
218
export LAUNCHPAD_ENV_BIN_PATH="$env_dir/bin"
167
219
export PATH="$env_dir/bin:$PATH"
@@ -174,6 +226,15 @@ __launchpad_switch_environment() {
174
226
fi
175
227
fi
176
228
fi
229
+
230
+ # Show completion time if verbose
231
+ if [[ "$verbose_mode" == "true" ]]; then
232
+ local end_time=$(date +%s%3N 2>/dev/null || echo "0")
233
+ local elapsed=$((end_time - start_time))
234
+ if [[ "$elapsed" -gt 0 ]]; then
235
+ printf "⏱️ [%sms] Shell integration completed\\n" "$elapsed" >&2
236
+ fi
237
+ fi
177
238
}
178
239
179
240
# CRITICAL: Prevent infinite loops - if we're already processing, exit immediately
@@ -186,17 +247,7 @@ export __LAUNCHPAD_PROCESSING=1
186
247
trap 'unset __LAUNCHPAD_PROCESSING 2>/dev/null || true' EXIT
187
248
188
249
# Basic shell integration with aggressive safeguards
189
- # Use verbose default if LAUNCHPAD_VERBOSE is not explicitly set
190
- local verbose_mode="${ verboseDefault } "
191
- if [[ -n "$LAUNCHPAD_VERBOSE" ]]; then
192
- verbose_mode="$LAUNCHPAD_VERBOSE"
193
- fi
194
-
195
- if [[ "$verbose_mode" == "true" ]]; then
196
- printf "⏱️ [0s] Shell integration started for PWD=%s\\n" "$PWD" >&2
197
- fi
198
-
199
- # Run the environment switching logic
250
+ # Run the environment switching logic (which handles its own timing)
200
251
__launchpad_switch_environment
201
252
202
253
# Clean up processing flag before exit
0 commit comments