fix(shell-hook): make prompt modification idempotent to prevent duplication#5686
Open
mango766 wants to merge 1 commit intoprefix-dev:mainfrom
Open
fix(shell-hook): make prompt modification idempotent to prevent duplication#5686mango766 wants to merge 1 commit intoprefix-dev:mainfrom
mango766 wants to merge 1 commit intoprefix-dev:mainfrom
Conversation
…cation Add guards to posix, PowerShell, and Nu shell prompt functions so that running `shell-hook` multiple times for the same environment no longer causes PS1 prefix duplication (bash/zsh), stack overflow from recursive prompt wrapping (PowerShell), or indefinite prompt nesting (Nu shell). Each prompt function now checks a `__PIXI_PROMPT_MODIFIED` env variable before modifying the prompt, making the operation idempotent. The fish shell prompt already had this guard via `functions -q __fish_prompt_orig`. Fixes prefix-dev#5599 Co-Authored-By: Claude (claude-opus-4-6) <noreply@anthropic.com>
Contributor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5599
Running
eval "$(pixi shell-hook ...)"multiple times for the same environment currently causes:(env) (env) (env) $promptfunction → stack overflow crashPROMPT_COMMANDRoot cause
The prompt modification functions in
crates/pixi_core/src/prompt.rs(posix_prompt,powershell_prompt,nu_prompt) unconditionally modify the shell prompt on every invocation, with no check for whether the prompt was already modified.Notably, the
fish_promptfunction already handles this correctly by checkingif not functions -q __fish_prompt_origbefore wrapping.Fix
Add an idempotency guard using a
__PIXI_PROMPT_MODIFIEDenvironment variable. Each prompt function now:__PIXI_PROMPT_MODIFIEDis already set to the expected value for the current environmentThis also correctly handles switching between environments — if you activate env A then env B, the guard value changes so the prompt gets updated.
Shells affected
@PROMPTreplaces)Test plan
eval "$(pixi shell-hook -m <project>)"twice in bash — PS1 should show(env)only once(pixi shell-hook) | Out-String | Invoke-Expressiontwice in PowerShell — no stack overflowtest_shell_hook_unix/test_shell_hook_windowstests should still pass