New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
starship init bash
in vscode: integrated terminal crashes due to infinite loop
#5816
Labels
🐛 bug
Something isn't working as expected.
Comments
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pkg_version:1.17.1
branch:master
commit_hash:
build_time:2024-01-02 18:32:30 +00:00
build_env:rustc 1.75.0 (82e1608df 2023-12-21),
Current Behavior
When using
eval "$(starship init bash)"
in my bashrc, when I start Visual Studio Code integrated terminal, it loads correctly, but if I try to source my bashrc manually during the session, the terminal crashes (and closes).Expected Behavior
The vscode integrated terminal does not crash when running
eval "$(starship init bash)"
twice in the same terminal.More context
If
eval "$(starship init bash)"
is not run as part of bashrc (or any sourced file at terminal startup), running it multiple times in the terminal works perfectly. The problem appears when it is executed at terminal startup. May be linked to how vscode handles its shell integration.My debug results
TL;DR: infinite loop caused by starship preserving
PROMPT_COMMAND
, and by vscode also preservingPROMPT_COMMAND
.Debugging details (click to unfold)
In vscode, with shell integration enabled (NOT the experimental ones),
PROMPT_COMMAND
is set to__vsc_prompt_cmd_original
(after sourcingbashrc
), and it overrides the value set by starship.vscode preserves
PROMPT_COMMAND
and executes it before its own__vsc_precmd
function.But starship does the same: it preserves
PROMPT_COMMAND
and executes it before its own logic instarship_precmd
.We can see it if we try to
echo $_PRESERVED_PROMPT_COMMAND
in.bashrc
. Because this is prompt related stuff, thebashrc
runs to completion, and the infinite loop is triggered after that, when the prompt needs to be printed.This is the source of the infinite loop.
__vsc_prompt_cmd_original
does not exist, andstarship_precmd
executes just finestarship init bash
again:PROMPT_COMMAND
is set to__vsc_prompt_cmd_original
(and it will executestarship_precmd
)PROMPT_COMMAND
as_PRESERVED_PROMPT_COMMAND
__vsc_prompt_cmd_original
executesstarship_precmd
starship_precmd
executes__vsc_prompt_cmd_original
as_PRESERVED_PROMPT_COMMAND
__vsc_prompt_cmd_original
executesstarship_precmd
Possible Solution
In starship.bash, add a verification specific to vscode:
PROMPT_COMMAND
is set to__vsc_prompt_cmd_original
PROMPT_COMMAND
${__vsc_original_prompt_command[@]}
does NOT containstarship_precmd
, add itEnvironment
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Relevant Shell Configuration
bashrc
Starship Configuration
Default (no file)
The text was updated successfully, but these errors were encountered: