Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow regex based regions to be clickable links #3821

Closed
salmankhilji opened this issue Jul 10, 2021 · 5 comments
Closed

Allow regex based regions to be clickable links #3821

salmankhilji opened this issue Jul 10, 2021 · 5 comments

Comments

@salmankhilji
Copy link

kitty allows clicking regions that look like URLs by manually looking for the pattern: known-prefix://url-chars within mouse.c.

I would like to see this feature expanded to accept any regex based pattern.

I have a script that pipes git log output to fzf. Each line looks like:

2575f3d4 ch12345 Git comment starts here

I'd like to be able to click on ch12345 to open it within a URL like: https://app.clubhouse.io/story/12345

Describe the solution you'd like
Re implement the URL detection feature to accept one or more regex patterns.

Describe alternatives you've considered

Attempt 1

Make my script detect the [cC][hH]([0-9]+) pattern and emit OSC 8 hyperlinks within each line.

Though this works just fine with kitty alone, when the script pipes git output to fzf --ansi, the latter eats up all hyperlinks as the give option does not go beyond processing ansi escapes.

Someone opened a similar bug on fzf more than 6 months ago; however, this issue has not been resolved to date.

Attempt 2

My next attempt was to add the following line to kitty.conf:

map kitty_mod+o pass_selection_to_program kitty-open-helper.sh
#!/bin/bash
if [[ "$1" =~ [cC][hH]([0-9]+) ]]; then
  xdg-open https://app.clubhouse.io/story/${BASH_REMATCH[1]}
else
  exec "$@"
fi

However, the UX is a bit awkward: rather than simply reaching for the text and clicking it, I have to first double-click to select it and then CTRL+SHIFT+O to open it. (One more keyboard shortcut to remember.)

It would be nice if I could simply reach out and click the ch12345 text without having to select it first.

Attempt 3

Implement the approach as described within the Hints section.

This would work, but is different than the mouse based solution I am trying to come up with.

@kovidgoyal
Copy link
Owner

I'm afraid not, using a regex is very slow, and in your case you would
need to first trigger the pattern using some key press, then click on
it, much less efficient than pressing a key to trigger hints and
then pressing another key to activate the selected hint.

And if you want to use the mouse the correct way is to mark the URLs
using escape codes, you would need to get fzf modified to pass those
through as well as formatting escape codes.

@ppwwyyxx
Copy link
Contributor

ppwwyyxx commented Nov 21, 2022

+1 for this feature. It's quite common for companies' internal tools to print short (no schema) urls that only makes sense with internal dns/browser extensions, or even just to save terminal space. Companies I worked for have used patterns like company.com/path, go/path, D12345, b/12345 as valid URLs. See also https://github.com/GoLinks/golinks#what-is-a-go-link and other users asking for this: alacritty/alacritty#2792

Currently I cannot configure kitty to recognize these regex (unlike alacritty or iTerm2, both support regex).

@howardjohn
Copy link

Sorry I know this is a super old issue but FWIW this was added to Alacritty. Its fairly handy IMO for the same reason the URL selection is or hyperlinks in general.

While it would be nice for every application to support hyperlinks directly its of course, not the case. Even modern applications like Rust which added native hyperlinks support (rust-lang/cargo#12888) only added it for a subset of desirable links, for instance. For example, doing something like opening a file from an compiler error output cannot be done without using hints, which requires keyboard usage rather than mouse.

To avoid the excess cause, a key modifier could be used. For example, only show matches will Shift is held, etc

@kovidgoyal
Copy link
Owner

kovidgoyal commented May 14, 2024 via email

@kovidgoyal
Copy link
Owner

I had a few minutes, so I implemented making the hints clickable. 8c1e365

Now just do

map f1 kitten hints --regex whatever --program -

then press f1 and click on whichever match you want and it will be inserted into your command prompt. You can of course change the invocation of the hints to do whatever action you like rather than inserting into the prompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants