Why does iTerm think that everything is a url?

1,043 views
Skip to first unread message

Aaron Meurer

unread,
Dec 10, 2013, 2:38:44 PM12/10/13
to iterm2-...@googlegroups.com
When I hold down command and hover my mouse over just about anything
in iTerm, it underlines it, and if I click it, it opens it as a url in
my browser, whether it really is a url or not. This is annoying
because I often accidentally do this when I'm trying to select
something. Did I screw up the settings somehow, or is this really the
intended behavior. I would prefer it if iTerm only tried to open
something if it actually looked like a legitimate web url.

On a somewhat related note, the one instance where this behavior would
be useful, it doesn't seem to work, namely, when I am inside of emacs,
I can't get it to open the url for the life of me. All
command-clicking does is move the cursor to where I clicked the mouse.

Aaron Meurer

George Nachman

unread,
Dec 10, 2013, 4:04:34 PM12/10/13
to iterm2-...@googlegroups.com
The existing behavior is obviously not ideal. However, almost anything *could* be a URL, so I erred on the side of completeness. Maybe requiring a slash would help with minimal losses. It would be great to resolve the hostname before underlining, but that could take too long.

If cmd-click isn't doing anything in emacs it's probably because mouse reporting is on, and that takes precedence. I suppose iterm shouldn't underline the links in this case, which is a bug. You can use cmd-alt-click to open links in this case (but the browser won't come to the foreground, because that's what cmd-alt-click does).





Aaron Meurer

--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

George Nachman

unread,
Dec 10, 2013, 5:02:14 PM12/10/13
to iterm2-...@googlegroups.com
I made some improvements. Try tomorrow's nightly build and let me know if it's ok.

Aaron Meurer

unread,
Dec 10, 2013, 5:12:50 PM12/10/13
to iterm2-...@googlegroups.com
I know that mouse reporting is taking precedence, but I would like to
request that when the item under the mouse is a url, that command
click take precedence.

For detecting urls, why don't you just use
http://blog.mattheworiordan.com/post/13174566389/url-regular-expression-for-links-with-or-without-the
?

Aaron Meurer

Aaron Meurer

unread,
Dec 10, 2013, 5:17:46 PM12/10/13
to iterm2-...@googlegroups.com
On Tue, Dec 10, 2013 at 3:12 PM, Aaron Meurer <asme...@gmail.com> wrote:
> I know that mouse reporting is taking precedence, but I would like to
> request that when the item under the mouse is a url, that command
> click take precedence.
>
> For detecting urls, why don't you just use
> http://blog.mattheworiordan.com/post/13174566389/url-regular-expression-for-links-with-or-without-the
> ?

Actually, that one could be improved, because it doesn't handle urls
with punction at the end, like "www.google.com.", which don't work in
many cases. But you get the idea. Isn't there something in the Cocoa
library that handles this?

Aaron Meurer

George Nachman

unread,
Dec 10, 2013, 5:21:18 PM12/10/13
to iterm2-...@googlegroups.com
The problem is that too many things are potentially URLs, and that would make the cmd-click behavior unpredictable. The regex you link to fails to catch a class of URLs that matter (at least to me and my colleagues), of the form hostname/argument, which is commonly used in the intranets of at least a couple big companies.

Stripping trailing punctuation should be safe to do. What is the set of trailing characters that should be removed? I'm thinking

.!)

Cocoa doesn't provide anything for picking URLs out of a string that I know of.

Leo R. Lundgren

unread,
Dec 10, 2013, 5:28:45 PM12/10/13
to iterm2-...@googlegroups.com
Please see https://code.google.com/p/iterm2/issues/detail?id=2589 for a feature request that could definately help solve this (by make the matching more flexible, allowing way more specific rules).

Aaron Meurer

unread,
Dec 10, 2013, 5:27:47 PM12/10/13
to iterm2-...@googlegroups.com
On Tue, Dec 10, 2013 at 3:21 PM, George Nachman <geo...@google.com> wrote:
> The problem is that too many things are potentially URLs, and that would
> make the cmd-click behavior unpredictable. The regex you link to fails to
> catch a class of URLs that matter (at least to me and my colleagues), of the
> form hostname/argument, which is commonly used in the intranets of at least
> a couple big companies.

Maybe make the regex user-modifiable. Or at least add options on what
sorts of things it catches. I understand the usage of hostname/stuff
but I don't ever see myself using it from the terminal, so I would
have no issue turning it off.

>
> Stripping trailing punctuation should be safe to do. What is the set of
> trailing characters that should be removed? I'm thinking
>
> .!)

And comma. I think ? too. Not sure about : and ;, but likely they are safe.

Aaron Meurer

Tom Feist

unread,
Dec 11, 2013, 9:16:41 AM12/11/13
to iterm2-...@googlegroups.com

On 10 Dec 2013, at 22:21, George Nachman <geo...@google.com> wrote:

> The problem is that too many things are potentially URLs, and that would make the cmd-click behavior unpredictable. The regex you link to fails to catch a class of URLs that matter (at least to me and my colleagues), of the form hostname/argument, which is commonly used in the intranets of at least a couple big companies.
>
> Stripping trailing punctuation should be safe to do. What is the set of trailing characters that should be removed? I'm thinking
>
> .!)
>

Note that stripping ')' can be problematic for things like wikipedia links, where you commonly encounter things like:
'https://en.wikipedia.org/wiki/Culture_(disambiguation)' (although they should correctly be encoded as %28/%29, but
in practice have been a common irritation in things like markdown parsers when they're not.

I'm not sure if there's a good solution that isn't massively overkill like trying to match balanced delimiters or
attempting to special-case (ugh) the obvious suspects.

One UX workaround might be to have the terminal highlight the match-under-cursor when cmd is held, so the user can
confirm the right bits are being {in,ex}cluded, and have the option to drag-select/refine otherwise.

I remember that auto-url highlighting is an old and rather tricky feature request, but iirc that was mostly performance
based, which requiring the keydown before scanning might solve.

Priority/Precision based list of regex rules similar to the smart selection might also help, or at least punt the problem
off to the user, if they often want to operate on weirdly-formatted urls :)

--Tom

Aaron Meurer

unread,
Dec 11, 2013, 2:21:55 PM12/11/13
to iterm2-...@googlegroups.com
On Wed, Dec 11, 2013 at 7:16 AM, Tom Feist <sha...@gmail.com> wrote:
>
> On 10 Dec 2013, at 22:21, George Nachman <geo...@google.com> wrote:
>
>> The problem is that too many things are potentially URLs, and that would make the cmd-click behavior unpredictable. The regex you link to fails to catch a class of URLs that matter (at least to me and my colleagues), of the form hostname/argument, which is commonly used in the intranets of at least a couple big companies.
>>
>> Stripping trailing punctuation should be safe to do. What is the set of trailing characters that should be removed? I'm thinking
>>
>> .!)
>>
>
> Note that stripping ')' can be problematic for things like wikipedia links, where you commonly encounter things like:
> 'https://en.wikipedia.org/wiki/Culture_(disambiguation)' (although they should correctly be encoded as %28/%29, but
> in practice have been a common irritation in things like markdown parsers when they're not.

In the same vein of what you just typed, I guess quotes should be
ignored (gmail ignored the "'", but not the ")").

>
> I'm not sure if there's a good solution that isn't massively overkill like trying to match balanced delimiters or
> attempting to special-case (ugh) the obvious suspects.
>
> One UX workaround might be to have the terminal highlight the match-under-cursor when cmd is held, so the user can
> confirm the right bits are being {in,ex}cluded, and have the option to drag-select/refine otherwise.

That's too complicated. Just open what you think the url is. If it's
wrong, you'll get a 404, and it will be clear (well, hopefully) that
the url is too much or not enough.

>
> I remember that auto-url highlighting is an old and rather tricky feature request, but iirc that was mostly performance
> based, which requiring the keydown before scanning might solve.
>
> Priority/Precision based list of regex rules similar to the smart selection might also help, or at least punt the problem
> off to the user, if they often want to operate on weirdly-formatted urls :)

Frankly, I would try to find some well-used library that has already
solved this, to at least borrow its regular expressions. Presumably
some common markdown renderers do the job well. Things like that that
match too much or too little tend to get bugged about it and it gets
fixed.

Aaron Meurer

>
> --Tom

George Nachman

unread,
Dec 11, 2013, 2:42:46 PM12/11/13
to iterm2-...@googlegroups.com
I think there's a fairly simple solution. You can already define regexes with priority/precision (prefs>profiles>advanced>smart selection) and assign actions that are added to the context menu when the current selection matches the associated regex. If you cmd-click in the terminal, we should apply the following rules:
1) Did you click on an existing filename? If so, use semantic history to open the file.
2) Perform smart selection. Did the highest-scoring regex have any actions associated? If so, perform the first action (they are ordered).
3) Do some segmentation (algorithm TBD) to pick out a URL, if any, and open it.

The algorithm in 3 could be a regex, but in looking around I didn't see any good ones using ICU regexes. Porting PCRE to ICU sounds painful!

George Nachman

unread,
Dec 15, 2013, 5:02:13 PM12/15/13
to iterm2-...@googlegroups.com
This is implemented in the latest nightly build. Also, potential URLs are shown underlined in their default color while a DNS query is performed. If the hostname is legit then it becomes blue, otherwise the underline disappears.

Aaron Meurer

unread,
Dec 16, 2013, 6:42:31 PM12/16/13
to iterm2-...@googlegroups.com
OK, the new behavior is much better. Is there any way to disable
opening of files? I don't really care about that (usually when I open
a file, I open it in the terminal anyway).

Also, going back to my other point, could you make it so that command
clicking on a valid URL overrides mouse reporting, so that it works in
emacs?

Aaron Meurer

Aaron Meurer

unread,
Dec 16, 2013, 6:49:44 PM12/16/13
to iterm2-...@googlegroups.com
I also noticed that the latest nightly likes to make a lot of annoying
noises every time something happens. How do I disable that?

Aaron Meurer

George Nachman

unread,
Dec 16, 2013, 8:22:50 PM12/16/13
to iterm2-...@googlegroups.com
Annoying noises? Like what?

There's no way to disable opening of files, but it's vanishingly unlikely that a URL is also an existing file on your local filesystem.

You can use cmd+alt+click to override mouse reporting. I'm leery of making mouse reporting more complex and less reliable (to be sure, someone will come along and complain that cmd-clicking on URLs breaks their app...)

Aaron Meurer

unread,
Dec 16, 2013, 8:38:27 PM12/16/13
to iterm2-...@googlegroups.com

On Dec 16, 2013, at 6:23 PM, George Nachman <geo...@google.com> wrote:

Annoying noises? Like what?

Yeah, the notification center stuff makes a noise each time. 


There's no way to disable opening of files, but it's vanishingly unlikely that a URL is also an existing file on your local filesystem.

I just cmd-clicked a file and it asked me if I wanted to open it in TextMate. 


You can use cmd+alt+click to override mouse reporting. I'm leery of making mouse reporting more complex and less reliable (to be sure, someone will come along and complain that cmd-clicking on URLs breaks their app...)

That seems to be doing too many things. It overrides mouse reporting and opens the URL in the background and enables rectangular selection. 

How could letting this work mess with mouse reporting? Cmd-click isn't reported as far as I know (correct me if I'm wrong).

Aaron Meurer

unread,
Dec 16, 2013, 9:56:05 PM12/16/13
to iterm2-...@googlegroups.com
On Mon, Dec 16, 2013 at 6:38 PM, Aaron Meurer <asme...@gmail.com> wrote:
>
> On Dec 16, 2013, at 6:23 PM, George Nachman <geo...@google.com> wrote:
>
> Annoying noises? Like what?
>
>
> Yeah, the notification center stuff makes a noise each time.

I figured out how to turn it off in the notification center settings,
but I would highly recommend making sound off the default.

Aaron Meurer

George Nachman

unread,
Dec 17, 2013, 1:01:52 AM12/17/13
to iterm2-...@googlegroups.com
You can disable notifications in prefs>profiles>terminal>send growl/notification center alerts. I've turned the sound off by default. That seems to be pretty common for notifications.

You're right that cmd-click isn't reported. In researching this, I discovered that opt-click is actually supported at the protocol level, but because we use option to disable mouse reporting, that's never used. Try tomorrow's nightly build and see what you think. Cmd-click gets passed through when mouse reporting is on as alt-click and also opens links.

Reply all
Reply to author
Forward
0 new messages