Mintty: Regex Hyperlink Matching and simplified opening

Created on 23 Nov 2018  ยท  10Comments  ยท  Source: mintty/mintty

I would like to be able to setup a regex with capture groups that can be turned into a hyperlink. An example is if the following text is on the terminal

See task T1234 for more details

I'd like to match it against T(\d+) and when I Ctrl+Click, it should open up the URL http://my.task.tracker.com/t=$1.

The issues #132 and #173 seem to be a good base to work off and they mention this pull request.

I think termmouse.c is the place to start looking, but can't figure it out. Could I get a hint?

enhancement help wanted

Most helpful comment

Released 2.9.7 with hyperlink support.

All 10 comments

Unclear; in what sense would you match against the regex, i.e. where would the regex come from?
Considering that URLs can be formed in lots of ways, how should the match be mapped to a URL?
This sounds like way beyond what a terminal can reasonably provide.

I'm explaining myself poorly, sorry.

Currently in mintty, when there is a hyperlink on the screen I Ctrl+click it and it opens a browser. Somewhere in mintty, there must be some code that registers http://stuff as clickable and somewhere else must say "Open that with the system browser" when it is clicked.

What I want to do is have some code that registers T(\d+) as clickable, then when it is clicked, turn it into a URL.

On a similar note, urxvt has matchers and terminator has plugins that will do this

Link detection is hard-coded and it always opens the plain link, not any substituted derivation.
Also I do not really see a strong use case for such transformation.
And there is no intent to add such complex configuration or even a plugin framework to mintty, sorry.

On the other hand, mintty has user-defined commands already. Check that out, I'd imagine you can achieve with it what you want.

I've added this example to the manual page, as a pattern:

UserCommands=google:/bin/cygstart https://www.google.de/search?q="$MINTTY_SELECT"

Then select your text, Ctrl+right-click, and choose menu item "google".

I'm trying to cut down on the number of steps to open up the web browser. For my case I know that T1234 should to to https://tasks.com/q=1234 and I don't want to have to select something from a menu. That's where the smart matching comes in.

Thanks for your time

We're talking about two things here:

  • Magic selection according to configured matching rules. As this is currently hard-coded (see the group of sel_spread functions in termmouse.c), it would mean a lot of fiddly work...
  • How to open selected text. If you'd be contented with manually selecting your match for now, this would be the easier part. I can image to assign the opening function to a mouse click or key press (like key shortcuts can be configured already, see option KeyFunctions).

As an alternative suggestion, mintty will support the OSC 8 protocol to set hyperlink attributes and explicitly mark text parts to open certain links. See Hyperlinks in terminal emulators for a discussion.

Released 2.9.7 with hyperlink support.

Assuming that the explicit hyperlink feature can also achieve the desired behaviour (although it requires a cooperating application), I'm closing the issue for now.

Was this page helpful?
0 / 5 - 0 ratings