lanoxx / tilda

A Gtk based drop down terminal for Linux and Unix
GNU General Public License v2.0
1.28k stars 161 forks source link

Use OSC 7 to get current working directory #309

Open egmontkob opened 7 years ago

egmontkob commented 7 years ago

tilda 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.

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: