From 21b7bf6009a672ad4a51f57ea96850834f528e31 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 12 Apr 2018 08:54:36 +0530 Subject: [PATCH] url_hints: Allow using a group to ignore prefix/suffix when matching via regex --- kittens/url_hints/main.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kittens/url_hints/main.py b/kittens/url_hints/main.py index ca5dddf98..a99e199b4 100644 --- a/kittens/url_hints/main.py +++ b/kittens/url_hints/main.py @@ -143,7 +143,7 @@ class URLHints(Handler): def regex_finditer(pat, line): for m in pat.finditer(line): - s, e = m.span() + s, e = m.span(pat.groups) if e - s > 2: yield s, e @@ -220,7 +220,9 @@ instead. --regex Instead of searching for URLs search for the specified regular -expression instead. +expression instead. If you specify a group in the regular expression +only the group will be matched. This allow you to match text ignoring a +prefix/suffix, as needed. --url-prefixes @@ -249,3 +251,10 @@ def handle_result(args, data, target_window_id, boss): w.paste(data['url']) else: boss.open_url(data['url'], None if program == 'default' else program) + + +if __name__ == '__main__': + # Run with kitty +kitten url_hints + ans = main(sys.argv) + if ans: + print(ans)