I find that ctrl clicking a file:///full-path-to-file hyperlink printed by a program in the terminal e.g. to stdout, assumes a full path in order to open the file in the default editor configured.

Is there a way to equivalently have hyperlinks that are relative paths, in the terminal? what might be the necessary syntax for that?

  • 1
    Like file:// + $PWD + some/relative/path? – muru May 20 '18 at 5:54
  • Not really, as that would translate to a full path before being emitted to the console wouldn't it?! – Matan May 21 '18 at 0:26
  • so what? You get to use relative paths in whatever emits this, the application gets to use absolute paths. Everybody's happy. – muru May 21 '18 at 0:28

The inherent problem with relative paths is: relative to what?

Relative to the working directory of the immediate child of the terminal emulator (typically: your shell) at the time of ctrl-clicking would be pretty much useless, all your links would break as soon as you cd away.

What you'd need at the very least is to be relative to the directory of the child process at the time the text is emitted. This raises some problems. First, the terminal emulator needs to be aware of its child's working directory (via e.g. the OSC 7 sequence, or some closer shell integration like in iTerm2), which then could still be incorrect during the execution of utilities that internally change their working directory (e.g. make). Moreover, emulators would need to remember this information for each and every printed character cell which could be quite expensive.

You might be interested in a pretty new feature of certain terminal emulators: explicit hyperlinks. Using a special sequence, the visible text can be turned into a hyperlink pointing to any location. The target of the hyperlink still needs to be specified as an absolute URI, yet the displayed text could be whatever you want (maybe just some relative pathname, or even something utterly different).

|improve this answer|||||
  • 1
    Hey great to learn about explicit hyperlinks.. didn't realize anyone was still working on better terminal windows! maybe one day they'll even understand up/down arrows and stuff :-) – Matan May 21 '18 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.