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

Directory and Document OSC escape sequences #3091

Closed
lloeki opened this issue Nov 12, 2020 · 3 comments
Closed

Directory and Document OSC escape sequences #3091

lloeki opened this issue Nov 12, 2020 · 3 comments

Comments

@lloeki
Copy link

lloeki commented Nov 12, 2020

Describe the solution you'd like

There's this macOS feature that adds semantic title bars. Terminal.app supports it through documented OSC escape sequences. It's really cool because an icon and a path (interpreted as such, and not just as a generic "title" string) is displayed by the OS, which is right-clickable to pop up the whole path, and clicking on any folder opens it in Finder right away.

As for the generic title string, there's also a distinction between tab title and window title.

In Kitty, implementing support for these escape sequences could enable additional placeholders for tab_title_template, such as {wd} and {document} in addition to the generic {title}. This would also make it possibly queryable as a property from kitty remote thus enabling clever scripting, and possibly, who, knows, help in someday implementing restoring windows cd'd into their initial directory.

Describe alternatives you've considered

  • Parsing the title string back, but it's error-prone, brittle, and kind of ludicrous
  • Use Terminal instead of Kitty ;)

Additional context

The inline doc for the sequences in Apple's Terminal:

Screenshot 2020-11-12 at 11 28 17

Screenshot 2020-11-12 at 11 27 37

The UI leveraging this metadata in action (notice the change in icons):

Screenshot 2020-11-12 at 12 06 16

Screenshot 2020-11-12 at 11 29 11

Screenshot 2020-11-12 at 11 29 17

Screenshot 2020-11-12 at 11 29 39

Screenshot 2020-11-12 at 11 29 45

Shell code that get called on working directory changes to set the "working directory" metadata, as well as the "window title" string (both get displayed independently in my current Terminal configuration, see example above):

set_term_title() {
    [[ -o interactive ]] || return
    # Bubble information up to the terminal
    case $TERM_PROGRAM in
        Apple_Terminal)
            local SEARCH=' '
            local REPLACE='%20'
            local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
            printf '\e]7;%s\a' "$PWD_URL"
            ;;
        *)
            # NOOP
            ;;
    esac
    case $TERM in
        screen*)
            #print -Pn "\ek%n@%m: %~\e\\" #breaks tmux
            print -Pn "\e]2;%n@%m: %~\a"
            ;;
        xterm*|*rxvt*)
            print -Pn "\e]2;%n@%m: %~\a"
            ;;
        *)
            # NOOP
            ;;
    esac
}

Vim code that sets the "document" metadata:

" Terminal title
set title
set t_ts=�]6;  " literal 0x1B char a.k.a ^[
set t_fs=     " literal 0x07 char a.k.a ^G
if !exists("autocmd_terminal_title")
  let autocmd_terminal_title = 1
  autocmd BufEnter,BufRead * let &titlestring = "file://" . hostname() . expand("%:p")
endif
@kovidgoyal
Copy link
Owner

Not a big fan of OS specific things, and if I ever want to open a finder
window in the current working directory of the active window, I'd just
create a mapping for it in kitty.conf rather than clicking with the
mouse using https://sw.kovidgoyal.net/kitty/launch.html

That said I wont refuse PR for it. Patches are most welcome. If you need
guidance with kitty's codebase, feel free to post on this thread and I
will help. You can get started with building kitty as described here:
https://sw.kovidgoyal.net/kitty/build.html

Closing this bug report, if anyone wishes to implemet it, feel free to
comment further.

@kovidgoyal
Copy link
Owner

Oh and FYI kitty has comprehensive controls for setting window and tab titles and much much more, https://sw.kovidgoyal.net/kitty/remote-control.html

@kidonng
Copy link
Contributor

kidonng commented Jun 22, 2021

FYI, this is called "Proxy icon" in macOS. Aside from Apple Terminal, iTerm2 also supports it (10th image).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants