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

Emit OSC-7 escape when changing directory #1147

Closed
dnkl opened this issue Aug 29, 2021 · 3 comments · Fixed by #1148
Closed

Emit OSC-7 escape when changing directory #1147

dnkl opened this issue Aug 29, 2021 · 3 comments · Fixed by #1148

Comments

@dnkl
Copy link
Contributor

dnkl commented Aug 29, 2021

Originally reported here: https://codeberg.org/dnkl/foot/issues/696; some users expect the terminal's builtin "spawn a new window" feature to open the new terminal window in nnn's current directory.

This works "automagically" on some terminals (which most likely dig through /proc to find out the current CWD of the leaf child process).

Others implement OSC-7, and escape that let's the application control which directory the terminal should consider to be the "current" one. Shells are often configured to emit this as part of rendering their prompts.

OSC-7 is pretty simple; just URL encode the directory and write \033]7;file://$HOSTNAME$CWD\033\\ (for example, \033]7;file://mini.la.casa/home/user/foobar\033\\). See e.g. https://codeberg.org/dnkl/foot/wiki#user-content-how-to-configure-my-shell-to-emit-the-osc-7-escape-sequence for a shell implementation. It is also documented here: https://iterm2.com/documentation-escape- codes.html.

It is implemented by at least VTE terminals, iTerm2 and foot.

Note that well behaving terminals ignore unrecognized OSC sequences, meaning it should be safe to emit OSC-7 unconditionally.

Note: avoid using localhost as hostname. The terminal matches the hostname to be able to ignore OSC-7 escapes from remote hosts (e.g. SSH).

Is it a "standardized" escape? It's not a VT escape, and not part of ECMA-48. So no, in that sense it's not standardized. There's an open issue over at terminal-wg, and one unmerged PR (unmerged due to too much bikeshedding). With that, I fully understand if this is a feature you want to pass :)

@jarun
Copy link
Owner

jarun commented Aug 29, 2021

The code should go here:

nnn/src/nnn.c

Line 6503 in c974690

Please share the exact printf() OR raise a PR. I don't own macOS so I can't test it.

@dnkl
Copy link
Contributor Author

dnkl commented Aug 29, 2021

Thanks! I'll see what I can do about opening a PR.

I don't own macOS so I can't test it.

FWIW you don't need macOS. It's also supported by libvte, and while I don't know if all VTE-based terminals therefore automatically support it, gnome-terminal should (not asking you to implement it though - just an FYI).

@jarun
Copy link
Owner

jarun commented Aug 29, 2021

I am on Xubuntu and tried with xfce4-terminal and it didn't work somehow. Can't really spend time on something that someone else already knows how to implement and test easily.

dnkl added a commit to dnkl/nnn that referenced this issue Aug 29, 2021
jarun pushed a commit that referenced this issue Aug 30, 2021
* Signal CWD change to terminal via OSC-7

Closes #1147

* Make OSC-7 emission gated by NOX11

* Use newpath variable in gethostname()
jarun pushed a commit that referenced this issue Aug 30, 2021
* Signal CWD change to terminal via OSC-7

Closes #1147

* Make OSC-7 emission gated by NOX11

* Use newpath variable in gethostname()

Use dynamic memory for hostname
@jarun jarun mentioned this issue Aug 30, 2021
4 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Sep 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants