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

OSC 133 (shell integration / semantic prompt) support #3064

Closed
vimpostor opened this issue Feb 10, 2022 · 8 comments
Closed

OSC 133 (shell integration / semantic prompt) support #3064

vimpostor opened this issue Feb 10, 2022 · 8 comments

Comments

@vimpostor
Copy link

vimpostor commented Feb 10, 2022

It would be good if tmux supported OSC 133, which is a control sequence that specifies where the prompt ended, and where the output of the executed program starts and ends.
This can then be used for some really helpful features, such as automatically scrolling to the beginning of the output of the last shell command, cycling between the last prompt inputs or selecting the entire output of the last ran command.

The spec can be found here: https://gitlab.freedesktop.org/Per_Bothner/specifications/blob/master/proposals/semantic-prompts.md
An example terminal emulator that implements this feature is wezterm: https://wezfurlong.org/wezterm/shell-integration.html

I am mainly interested in the OSC 133 part, the OSC 7 part can be considered a separate issue.

Is this something that you would be willing to accept into the tmux codebase? If so, I can implement this myself in the near future.

This control sequence has to be supported from the shell, for example in the case of zsh one could use powerlevel10k and enable it by setting POWERLEVEL9K_TERM_SHELL_INTEGRATION=true.

@vimpostor vimpostor changed the title OSC 133 (shell integration) support OSC 133 (shell integration / semantic prompt) support Feb 10, 2022
@nicm
Copy link
Member

nicm commented Feb 10, 2022

Something like this has been on the todo list for ages:

Marked positions in history. Could use the same prompt-detection escape sequences as iTerm2. Could be listed by capture-pane and also a menu to jump to marks in copy mode. (#1042) is related and also has some code to display a marker line.

So if you want to have a go, that would be great :-). You will need to decide what "support" means - what is tmux going to do with this information, how will the UI and commands to use the new features work, etc.

@nicm
Copy link
Member

nicm commented Feb 10, 2022

If I was you I would probably pick a simple feature you want this to do (for example, a flag to copy-mode to enter copy mode and scroll to the most recent mark, or whatever) and implement that first, that would get the escape sequences and how the marks are going to be stored sorted out. Then any more sophisticated features could be built on top of that.

I don't think it is necessary to go beyond the basic support for the feature (look at https://iterm2.com/documentation-escape-codes.html), the extensions in the proposal don't look of much use.

@nicm
Copy link
Member

nicm commented Feb 10, 2022

BTW tmux has supported OSC 7 since f3dc38d, but we do not currently do anything with it apart from make it available in a format variable.

@vimpostor
Copy link
Author

I agree, the main selling point is being able to jump between the last commands. Other stuff like selecting the entire last output could easily be added later.

For cycling between the last commands I would add the following new commands (not sure if they should have a keybinding by default).

  • previous-command (or maybe name it previous-prompt alternatively): Goes to the beginning of the previous command in history relative to the current position in copy-mode. If copy-mode is not currently active, enter copy-mode and go to the beginning of the last command.
  • next-command: Go to the next command in history relative to the current position in copy-mode.

Both would position the view such that the prompt of the respective command is the first line visible in the window (at the top of the window).

@nicm
Copy link
Member

nicm commented Feb 10, 2022

If you add them as copy mode commands, then a key binding can be:

copy-mode; send -X jump-to-previous-command

@nicm
Copy link
Member

nicm commented Feb 16, 2022

I'm closing to close this for the moment but feel free to ask here if you have any further questions, or open a PR if you have code you want me to look at. Thanks!

@nicm nicm closed this as completed Feb 16, 2022
@vimpostor
Copy link
Author

Yes I will send a patch soon, don't worry I haven't abandoned the idea, just a little busy at the moment.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants