✨ Stop editing users zsh file in order to set the terminal tab title
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!
@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.
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.
@austincondiff Can you assign this to me please?
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.
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)
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.