Skip to content
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

feat: Set terminal title to indicate atuin tui is active #2215

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fidgetingbits
Copy link

Attempts to address #2214 for zsh. Currently this just naively changes the title to "atuin" and back to "zsh". The default zsh settings will auto update the title (unless using zsh setting DISABLE_AUTO_TITLE="true"), so possibly setting it back to "zsh" afterwards isn't even needed.

afaict it's not possible to query the current title, so we can't switch it back to what was originally there. So I think this does run the risk of clobbering someones title, if they have set DISABLE_AUTO_TITLE="true", in which case it may be best to have an atuin option that's default to off? I figured I'd send this PR to show the idea anyway, since it's working for my use case, and can start a discussion about how best to do it.

Copy link
Contributor

@akinomyoga akinomyoga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I naively think that maybe we can output the OSC sequences from atuin search. Then, we don't have to write the settings for each shell.

Also, it would be better if we could configure the title during atuin search and that after atuin search.

@fidgetingbits
Copy link
Author

I naively think that maybe we can output the OSC sequences from atuin search. Then, we don't have to write the settings for each shell.

Also, it would be better if we could configure the title during atuin search and that after atuin search.

I like that idea and had considered it. The main thing I wasn't so sure about is, is what to set it back to, since each shell has some default (and different) title behavior I think. So just opted to do it per shell to start. Being able to just enable it with a setting would be great since most users likely don't care about it, and would be much easier by adding it to atuin search.

So do you envision a setting that toggles the behavior on/off, a setting for what the title is when the TUI is open (default to 'atuin' maybe), and another one for what to reset it to? Probably the title to reset to could default to nothing (so not change it), as many shells (like zsh) would auto-reset it on it's own anyway?

@akinomyoga
Copy link
Contributor

First, I think we should make this feature opt-in, i.e. it would set the terminal title only when it is turned on by the configuration. The users can have their own settings for the terminal title. This feature overwrites the users' settings if it is enabled by default. The users who want Atuin to set the terminal title can enable this feature explicitly. Then, the user can set the reset sequence to the desired one.

I like that idea and had considered it. The main thing I wasn't so sure about is, is what to set it back to, since each shell has some default (and different) title behavior I think.

  • I'm not a user of Zsh, but Zsh doesn't seem to change the title by default. This PR changes back the title to zsh, but is this really Zsh's behavior? For example, the zsh-term-title plugin you mentioned in Feature Request: Set terminal title when interactive mode is launched via shell hooks #2214 seems to set it to a somewhat different string: the command name plus the directory name. Is zsh your personal preference or needed by "talon" you mentioned in Feature Request: Set terminal title when interactive mode is launched via shell hooks #2214? Meanwhile, Fish seems to set the terminal title by default to the directory name by default, while Bash doesn't set the terminal title by default. It seems to me that even if the shell is known, it is in general difficult to reset the title to the one that the user expects.
  • If the terminal title can be just reset to the shell name (as in this PR), atuin search may detect the parent shell and switch the behavior, though I'm not sure if that is useful.
  • As another possibility, one can use the push/pop terminal title sequences, XTWINOPS(22) and XTWINOPS(23), but this is not implemented by many terminals and might cause error messages in the terminal not supporting them.

Being able to just enable it with a setting would be great since most users likely don't care about it, and would be much easier by adding it to atuin search.

Yeah, that would be what I suggest.

So do you envision a setting that toggles the behavior on/off, a setting for what the title is when the TUI is open (default to 'atuin' maybe), and another one for what to reset it to?

Yeah, or the toggling option can be omitted by allowing the title to be empty; the empty title means that the feature is turned off.

Probably the title to reset to could default to nothing (so not change it), as many shells (like zsh) would auto-reset it on it's own anyway?

I'm not sure, but I think the terminal title is usually configured to be updated after a user command is executed. I'm not sure if we can expect that the shell settings will reset the title after each keybinding in general.

@fidgetingbits
Copy link
Author

First, I think we should make this feature opt-in, i.e. it would set the terminal title only when it is turned on by the configuration. The users can have their own settings for the terminal title. This feature overwrites the users' settings if it is enabled by default. The users who want Atuin to set the terminal title can enable this feature explicitly. Then, the user can set the reset sequence to the desired one.

Okay, I agree with this. I suspect the majority of users won't use it as it's mostly an accessibility thing, so opt-in totally makes sense.

* I'm not a user of Zsh, but Zsh doesn't seem to change the title by default. This PR changes back the title to `zsh`, but is this really Zsh's behavior? For example, the `zsh-term-title` plugin you mentioned in [Feature Request: Set terminal title when interactive mode is launched via shell hooks #2214](https://github.com/atuinsh/atuin/issues/2214) seems to set it to a somewhat different string: the command name plus the directory name. Is `zsh` your personal preference or needed by "talon" you mentioned in [Feature Request: Set terminal title when interactive mode is launched via shell hooks #2214](https://github.com/atuinsh/atuin/issues/2214)? 

I do match on "zsh" using talon, but can match on anything unique as long as something is set. I just double checked a vanilla terminal without my voice coding setup loaded and you're right, it's not set to zsh by default, it's set to the cwd.

Meanwhile, Fish seems to set the terminal title by default to the directory name by default, while Bash doesn't set the terminal title by default. It seems to me that even if the shell is known, it is in general difficult to reset the title to the one that the user expects.

Agreed.

* As another possibility, one can use the push/pop terminal title sequences, [`XTWINOPS(22)`](https://terminalguide.namepad.de/seq/csi_st-22/) and [`XTWINOPS(23)`](https://terminalguide.namepad.de/seq/csi_st-23/), but this is not implemented by many terminals and might cause error messages in the terminal not supporting them.

Cool! Never heard of that. But ya, I'd probably just opt to not bother so special casing various terminals isn't required.

Being able to just enable it with a setting would be great since most users likely don't care about it, and would be much easier by adding it to atuin search.

Yeah, that would be what I suggest.

So do you envision a setting that toggles the behavior on/off, a setting for what the title is when the TUI is open (default to 'atuin' maybe), and another one for what to reset it to?

Yeah, or the toggling option can be omitted by allowing the title to be empty; the empty title means that the feature is turned off.

Ya that's simpler.

Probably the title to reset to could default to nothing (so not change it), as many shells (like zsh) would auto-reset it on it's own anyway?

I'm not sure, but I think the terminal title is usually configured to be updated after a user command is executed. I'm not sure if we can expect that the shell settings will reset the title after each keybinding in general.

Okay, thanks for all the feedback. I'll work on adding it to atuin search and update the PR/issue accordingly.

@fidgetingbits fidgetingbits marked this pull request as draft July 2, 2024 09:24
@fidgetingbits fidgetingbits changed the title feat(zsh): Set terminal title to indicate atuin tui is active feat: Set terminal title to indicate atuin tui is active Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants