179

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.

japetheape
  • 1,900
  • 2
  • 12
  • 6

4 Answers4

405

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

Joshua Muheim
  • 12,617
  • 9
  • 76
  • 152
oops
  • 5,539
  • 1
  • 18
  • 10
  • 2
    Too bad there's no way to do this to, say, open filesystem links in finder – Peter Ehrlich Oct 11 '12 at 16:44
  • 1
    Note: It was ⌘ + double-click on 10.4, changed to ⌘ + ⇧ + double-click in 10.5, then back again in (I think) 10.6. Source: I reported a bug on 10.5 when it was released that ⌘ + double-click no longer worked, received the reply "It’s now cmd-shift". – Drarok Jul 04 '13 at 10:56
  • 3
    You can actually just do `cmd` + `click` – Steve Jan 22 '16 at 13:32
  • @oops Is there official Apple documentation on this? How did you figure this out? – trinth Sep 05 '18 at 00:19
  • 2
    Is there a way to get bash to print it highlighted? I know some IDEs with shells do this, so I figure it _should_ be possible – karl Sep 07 '18 at 19:08
  • saved my day, first google try, found your answer - bingo.... thats all i needed! – Florian Eck Apr 18 '19 at 23:40
  • This is useful information, but don't actually answer the question. – Leonardo Raele Nov 28 '19 at 18:57
  • @PeterEhrlich if you have control over the file system links that are showing up in your Terminal, you can prepend them with "file://" to make it work. Can't open a url for `/Volumes/foo`, but can open `file:///Volumes/foo` – Aaron Jun 13 '20 at 02:07
  • works in 2022 – gndps Jun 22 '22 at 21:03
36

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 ?

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • 1
    No as it must serve my development cycle this won't be fast enough. The best solution would be displaying only a text, with a link behind it that is not displayed, however as far as my bash/sh knowledge goes, I think this is not possible, hope you prove me wrong ;-). – japetheape Feb 26 '10 at 00:55
  • 1
    I had always been selecting the URL first (dragging the cursor from the start to end of the URL), then right clicking. I learned today, while reading through these answers, that it was not necessary to select the URL; simply right clicking on it works. This was much faster, but @oops's answer is faster, still. – Jimothy Oct 27 '15 at 21:13
  • 1
    Awesome. Am I the last person in the world to learn this on-handed trick? – anthumchris Jun 12 '19 at 19:31
4

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.

-7

Pipe your output to lynx:

your_command | lynx -use_mouse -stdin
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
  • I tried this: echo "Test" | lynx -use_mouse - stdin This opens lynx, this is not what i want, I want the output directly in my terminal. – japetheape Feb 26 '10 at 01:49
  • Bash won't do it. I don't know why PS1 should have anything to do with it. I don't believe Bash has any mouse support whatsoever. If Terminal.app only does it with a right click, then your only other option may be if you can write an AppleScript that will provide that functionality more directly. Or magic. – Dennis Williamson Feb 26 '10 at 01:59