Create clickable links in terminal

6,927

Solution 1

Newer version of GNOME terminal now support hyperlinks with custom target via certain escape sequences. Try

echo -e '\e]8;;http://example.com\aThis is a link\e]8;;\a'

Opening these works the same way as described in the answer by Stephen Kitt. To address the problem you described you could use a sed script (or some more advanced method) to translate the file names into hyperlinks. For me the following does the job (in bash and assuming the above way to create hyperlinks works)

grep "mServiceIntent" -R ./src/ | sed -e $'s#^\(.*\):#\e]8;;file:'`pwd`/$'\\1\a\\1\e]8;;\a#'

(I do not have sublime installed but most likely you can simply change file: into slbm:)

See also: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda (This is based on my answer at Terminal - create hyperlinks)

Solution 2

It's a computer; you can program it. :-)

To make something "clickable" means either programming a GUI application or somehow using HTML. The simplest way I can think of would be to generate an HTML page of HREFs, and pipe the output to, say, lynx, configuring the browser to open emacs appropriately.

Share:
6,927
Kein
Author by

Kein

Updated on September 18, 2022

Comments

  • Kein
    Kein over 1 year

    Is it possible to process/transform the output from grep (or produce grep-like results, finding strings and/or patterns in files, some other way) such that the search results can be used as links (i.e., hyperlinks) to open an editor?  I want to click on a filename:line_number in my grep result and open my editor at the selected line.

    $ grep "mServiceIntent" -R ./src/
    ./src/example/PhotoThumbnailFragment.java:67    private Intent mServiceIntent;
    ./src/example/PhotoThumbnailFragment.java:194        mServiceIntent =
    ./src/example/PhotoThumbnailFragment.java:203        getActivity().startService(mServiceIntent);
    

    I know how to register protocols in the system to open the editor.  For example, all URLs like sblm://* in my system open in Sublime Text.  My question is: how to create custom links in guake terminal (or maybe it doesn't depend on quake and works for default terminal program)?

    Note: the related(?) question, Is there a terminal app that allows filenames to be clickable?, is vague on specific implementation/solution details, and doesn't explicitly mention my requirement to jump directly to an identified line in the file.

  • Marius Gedminas
    Marius Gedminas almost 5 years
    See also purpleidea.com/blog/2018/06/29/hyperlinks-in-gnome-terminal for the urlencode bash function that makes things work correctly when you have spaces or other interesting characters in directory/file names.
  • dykeag
    dykeag over 3 years
    This does not answer the question as asked - he does not want to reinvent the wheel by creating an entirely new terminal GUI.