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.