! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Use OSC 7 to get current working directory
Status:
RESOLVED: FIXED
Product:
Xfce4-terminal
Component:
General

Comments

Description Egmont Koblinger 2017-10-05 21:35:36 CEST
xfce4-terminal preserves the working directory when opening a new tab, and does so by digging under /proc to figure out the current directory of the child process (shell) it's running.

This approach has several limitations. It is heavily OS dependent. It cannot preserve symlink components. It only works with the direct shell (unless you do even more complex digging under /proc) and stops working when the user runs screen/tmux or su/sudo or something similar.

GNOME Terminal version 3.8-ish has changed to a new model, taken from Mac's Terminal.app. The OSC 7 escape sequence explicitly tells the working directory to the terminal emulator. This approach is used now by many other terminal emulators, including (but not necessarily limited to) VTE-based Tilix and Terminix, as well as recent versions of Konsole.

Please consider switching to this new method, possibly with a fallback to the old one if no OSC 7 has been encountered in the given terminal, or possibly without this fallback.

Advantages: Cleaner code. Possibility to preserve symlinks. More consistency with other terminal emulators. Works from within screen/tmux or friends. There's a pending patch to make it work from Midnight Commander too [1].

Disadvantages: The user needs to source /etc/profile.d/vte-2.91.sh to set up the necessary PROMPT_COMMAND for bash or zsh. Distros suck at setting this up by default, and ideally this should go to something like /etc/bashrc.d since it needs to be sourced by non-login shells too, but typically there's no such directory in distros.

What you need to do:
- Call vte_terminal_get_current_directory_uri()
- Extract and decode the directory somehow (e.g. g_filename_from_uri())
- Preferably refuse if the hostname part doesn't match the actual hostname (and isn't empty or "localhost" either)
- Set the env var PWD to preserve symlinks due to bug [2]; no longer needed once we address that bug

[1] https://www.midnight-commander.org/ticket/3088
[2] https://bugzilla.gnome.org/show_bug.cgi?id=758452
Comment 1 Igor editbugs 2017-10-06 17:27:26 CEST
Hi Egmont, thanks for keeping eye on xfce4-terminal and reporting this!

I've add the functionality with https://git.xfce.org/apps/xfce4-terminal/commit/?id=ff1419604d928c37bef10889e10ab2657cc091d3
I kept the old code just in case vte_terminal_get_current_directory_uri() doesn't work: when vte-2.91.sh hasn't been sourced, for instance.

Bug #13902

Reported by:
Egmont Koblinger
Reported on: 2017-10-05
Last modified on: 2017-10-06

People

CC List:
0 users

Version

Version:
unspecified

Attachments

Additional information