Is there a way to make a link clickable in the OSX Terminal?

BashMacosTerminalTextmate

Bash Problem Overview


I am planning on developing an Mxmlc to Textmate formatter, one that formats mxmlc errors as clickable links, so you can open them up quickly in Textmate as Textmate has a url scheme e.g.: txmt://open/?url=file://~/.bash_profile&line=11&column=2.

I am wondering if it is possible to display links in your OSX terminal, that are also clickable, e.g. by changing the PS1 variable or so.

ps. I don't want to use HTML that runs in the Textmate environment.

Bash Solutions


Solution 1 - Bash

Before OSX Lion:

cmd+shift+double-click on a URL in Terminal.app and it will open in the default program.

OSX Lion:

cmd+double-click (otherwise you will enter fullscreen mode).

Solution 2 - Bash

You can right click on a URL in Terminal and the first option in the context-sensitive menu is "Open URL". Not perfect, but maybe good enough ?

Solution 3 - Bash

Others have discussed how you can select and Command-click on text which is a valid URI. As for Command-clicking on an embedded hyperlink, just like an anchor in hypertext (i.e., where the displayed text is not the URI itself), I believe the short answer is: Terminal cannot do it, but iTerm2 can.

Bash (or any other program that prints to a tty) can output the appropriate escape sequence to create a clickable hyperlink: it is \x1B]8;;URI\x1B\\TEXT\x1B]8;;\x1B\\, where \x1B represents the escape character, \\ represents a literal backslash, URI is the URI you want to link to (starting with https://, file:///, or whatever), and TEXT is the text you want to actually appear, for the user to Command-click on. (You can also use \a, the alert or bell character, instead of both instances of \x1B\\, but I understand this is less standard.) For example:

>See \x1B]8;;file:///path/to/help/file\x1B\\the help file\x1B]8;;\x1B\\ for details.

In Mac OS(X), under El Capitan in my case, this works perfectly with iTerm2, and shows:

>See the help file for details.

except that the linked text the help file has a dotted underline instead of being in italics. Command-clicking anywhere on the linked text opens the specified URI in the default browser. (Incidentally, this is also the behaviour in the Terminal program in Ubuntu Linux.)

In Mac OS(X) Terminal, you just get:

>See the help file for details.

with no special typography and no ability to Command-click on any part of it.

You can get the full detail, including a list of supporting terminals, at https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda.

Solution 4 - Bash

Pipe your output to lynx:

your_command | lynx -use_mouse -stdin

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjapetheapeView Question on Stackoverflow
Solution 1 - BashoopsView Answer on Stackoverflow
Solution 2 - BashPaul RView Answer on Stackoverflow
Solution 3 - BashJason JohnstonView Answer on Stackoverflow
Solution 4 - BashDennis WilliamsonView Answer on Stackoverflow