-
Notifications
You must be signed in to change notification settings - Fork 500
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
bash: seeing extra leading character '[' in command output #4494
Comments
@jparise Thanks for converting. I can't tell from the discussion but did you get a lead on what is causing this? More importantly: do you have an easy reproduction? |
Unfortunately, no to both. I tried a bunch of things myself (details in the discussion), but I haven't been able to reproduce or identify the root cause. Multiple people have seen it in various Linux environments though. |
@jparise I'm happy to assist in creating an environment in which this is reproducible. Let me know if you want an extra set of hands on this. |
Yes, that would be very helpful. Thanks for the offer! |
I have replicated the issue outside of Ghostty (eg in Gnome Terminal) on NixOS. Setup:
I tried putting traces before and after all of the printf calls as well as the PS* entries and the '[' still prints before all of them. I don't believe the issue to be related to the prompt. |
I had a bit of time this morning and have tracked down the issue. Long story short, It's an interaction with vte.sh and the PS0 prompt it sets, however I do not understand what the exact issue their PS0 which is set to Setting PS0 to "" at the top of the This explains why it exhibits the issue when launched from gnome-terminal (or any VTE based terminal emulator) but not from the DE launcher menu. Launching from xterm also works as expected without the extra output. |
Great! That's super helpful, and I really appreciate the time you spent tracking down the root cause. I'll spend some time thinking about the best solution. |
A few things I've learned:
@vhodges, would you be able to take a closer look at these items to verify my understanding? |
These are the two places where we use
We could also narrow down the source of the conflict by disabling each/both of those shell integration features. @mattxtaz noticed that this could be limited to |
Oh sorry, I forgot to mention I isolated it to the cursor related code. On my system, line 116 sets PS0 vte.sh does bailout early if it's a non-interactive shell. It also exits if it's not running in a VTE terminal emulator. This is why I think the issue does not occur when running Ghostty from the DE or from an xterm. Launching a gnome-terminal (by definition interactive) and starting Ghostty from that shell is inheriting the env from it (and so PS0). It's not a conflict so much as a weird side effect of launching it from an existing terminal. Launching Ghostty from a gnome-terminal and running the following from the Ghostty terminal window indicates the env is inherited. Perhaps the fix is to unset VTE_VERSION so the vte.sh code just exits. Let me try that... [EDIT: Does not work and of course it would never work since it's already been run]
Here is the bash specific code from vte.sh (on my system)
|
We already have some code to "clean up" certain environment variables before launching a new shell, perhaps we should unset Lines 836 to 864 in 3461204
|
unsetting VTE_VERSION does not work since PS0 is already set by vte.sh before running Ghostty (obvious in hindsight) |
What if you unset |
Ah yes, unsetting VTE_VERSION before starting Ghostty works. |
But this is outside the scope of what we can do (as a project) to help this situation, right? |
We already do some of this. It's arguable if this is "in scope" or "out of scope". I think that by injecting our integration into the shell it's in scope to make this work as it's obviously caused a lot of issues for people. Also, removing the "VTE_VERSION" string prevents us from advertising that the TUI app is running in a VTE-based terminal emulator. Lines 836 to 864 in 3461204
|
My thought was that it's a reasonably clean solution as suggested by @jcollie to unset it before starting the shell since there's no reason to have that code run for Ghostty and this would ensure that (unless they change vte.sh to not check for it). I do agree that it's a less than ideal thing to have to do to work around something that is so invasive to peoples systems that is unrelated otherwise to this project. |
Ah, I took "before starting Ghostty" as literally meaning "before any part of Ghostty runs". It sounds like "before starting Ghostty" means "before executing the command process". I'm totally aligned with removing
|
Sorry, again I was not clear. Unsetting it in ghostty.bash did not work but doing that before starting ghostty did but this just removes it from the env of the command process without having to recompile. (Posting from work) |
@vhodges would you mind looking over this vm gist. I can't reproduce the behaviour you're seeing with that vm definition. Perhaps I'm missing something else specific to your system? Testing steps taken:
|
This variable is set by gnome-terminal and other VTE-based terminals. We don't want our child processes to think we're running under VTE. See #4494
@anund I ran the VM and indeed it does not exhibit the issue! One difference (that I would not think matter): I am running X11/Cinnamon DE. Other than that I am at a loss. |
The latest tip release includes #4710. It would be fantastic if that addressed the root cause of this issue. |
I can confirm 1.0.2 fixes the issue I was seeing. |
Given that confirmation, I'm going to close this as fixed. Yay! We can reopen/recreate if we discover any other cases that need further investigation. |
Discussed in #3566
Originally posted by jharshman December 27, 2024
After compiling from source and running I am seeing an extra character in the output of every command. Is anyone else experiencing this? Shell is Bash and no modifications to the PS1.
The text was updated successfully, but these errors were encountered: