Skip to content

✨ Stop editing users zsh file in order to set the terminal tab title #1640

Closed

Description

@TeddyHuang-00

I am using xonsh which will source zshrc from its own rc file. However, I found the current shell integration injection (the code below) breaks the zsh grammar.

https://github.com/CodeEditApp/CodeEdit/blob/8f26014ee26597b2def50601a8c07452142bee8b/CodeEdit/Features/TerminalEmulator/TerminalEmulatorView.swift#L171C2-L182C14

This can be easily fixed if the following line

[[ "$TERM_PROGRAM" == "CodeEditApp_Terminal" ]] && . "/Applications/CodeEdit.app/Contents/Resources/codeedit_shell_integration.zsh"

was rewritten to

if [[ $TERM_PROGRAM == "CodeEditApp_Terminal" ]]; then
  source "/Applications/CodeEdit.app/Contents/Resources/codeedit_shell_integration.zsh"
fi

This is IMO a more compatible way to write these lines.

PLUS, I think it is a necessity to notice the users when manipulating their shell rc files! Not everyone will welcome unexpected rc file change!

Activity

  1. austincondiff commented on Mar 19, 2024

    @austincondiff
    Collaborator

    @TeddyHuang-00 I'd agree, and if possible I'd like to avoid modifying the rc files in the first place.

    I think this was put in place to attempt to label the tab that represented each terminal in the utility area. I honestly think that there is a better way to do this that doesn't require us to modify the users rc file.

    See this issue for context.

  2. TeddyHuang-00 commented on Mar 19, 2024

    @TeddyHuang-00
    Author

    I honestly think that there is a better way to do this that doesn't require us to modify the users rc file.

    @austincondiff Yes, there are definitely methods out there that can achieve this without messing with rc files. Existing terminal emulators like iTerm2 and alacritty are able to do this without modifying the rc files.

    See this issue for context.

    I tracked the dialogue a little bit, and can tell that all the shell integration does is to add hooks before and after command execution to raise escape sequences for CodeEdit to process.

    I suspect that by setting the terminal type $TERM to some well-established values (e.g. xterm-256color) will automatically raise those escape sequences, though the exact escape sequences might differ based on this value chosen.

    Due to my lack of knowledge in this project and Swift, I cannot offer any further help in implementing this, but I honestly think this is a more rational way to achieve this and hope it will be adopted.

  3. changed the title [-]Improve shell integration[/-] [+]✨ Stop editing users zsh file for setting the terminal title as the terminal tab title[/+] on Mar 23, 2024
  4. Qubik65536 commented on Mar 23, 2024

    @Qubik65536
    Contributor

    @austincondiff Can you assign this to me please?

  5. Qubik65536 commented on Mar 23, 2024

    @Qubik65536
    Contributor

    Here's a simple progress report.

    What we'll do

    At the moment, following the weekly meeting today, we decided to directly fix this issue by no longer write anything in user's rc file. So this syntax won't be fixed in a short period of time (or forever if everything goes well).

    Shell Integration scripts

    As far as I can tell, hook scripts (like codeedit_shell_integration.zsh that we have right now) are required. No $TERM settings will enable this or add any escape sequence, it's all terminal app developers' work.

    As a reference, here's what VSCode and iTerm2 are doing.

    What's the fix?

    As our entire approach is more similar to iTerm, we might try to use a similar solution to theirs. Here's their code.

  6. changed the title [-]✨ Stop editing users zsh file for setting the terminal title as the terminal tab title[/-] [+]✨ Stop editing users zsh file in order to set the terminal tab title[/+] on Mar 24, 2024
  7. added this to the v0.2.0 milestone on Mar 31, 2024
  8. moved this from 🆕 New to 📋 Todo in CodeEdit Projecton Mar 31, 2024
  9. thecoolwinter commented on Jun 2, 2024

    @thecoolwinter
    Collaborator

    After doing some research, it looks like iTerm2 does require users to edit their rc file manually to use their terminal integration feature (docs). What VSCode does (and what seems like a good option) is they set the init file to a temporary directory which includes their own init files. These scripts have hooks for a few VSCode features, and eventually source the user's init files after setting up their own (VSC's rc.zsh file, Where shell injection happens). Or, for bash, they emulate what bash does for init. They pass their own script as the init file, and then execute the user's init file depending on what exists (bash_profile, bash_login, then profile, see this file)

  10. thecoolwinter commented on Jun 11, 2024

    @thecoolwinter
    Collaborator

    I have this working and tested for both bash and zsh. I'll open a PR later today. We'll also enable users to opt-out of using the injection mechanism in settings.

  11. moved this from 📋 Todo to 🏁 Complete in CodeEdit Projecton Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions