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

Make hyperlinked_grep kitten respect context options #3759

Merged
merged 1 commit into from
Jun 24, 2021
Merged

Make hyperlinked_grep kitten respect context options #3759

merged 1 commit into from
Jun 24, 2021

Conversation

allemangD
Copy link
Contributor

I want to start using the hyperlinked_grep kitten, but it currently ignores the context options, which I use frequently. Some sample expected output:

$ rg -C 1 'write_hyperlink' kittens
kittens/hyperlinked_grep/main.py
14-
15:def write_hyperlink(write: Callable[[bytes], None], url: bytes, line: bytes, frag: bytes = b'') -> None:
16-    text = b'\033]8;;' + url
--
47-                if m is not None:
48:                    write_hyperlink(write, in_result, line, frag=m.group(1))
49-                else:
--
54-                    in_result = b'file://' + hostname + path
55:                    write_hyperlink(write, in_result, line)
56-                else:

But the kitten does not output context:

$ kitty +kitten hyperlinked_grep -C 1 'write_hyperlink' kittens
15:def write_hyperlink(write: Callable[[bytes], None], url: bytes, line: bytes, frag: bytes = b'') -> None:
48:                    write_hyperlink(write, in_result, line, frag=m.group(1))
55:                    write_hyperlink(write, in_result, line)

Here, I fix the num_pat regex so that context lines are hyperlinked. I also also add a case so that any non-matching lines (like the -- separators) are still output without hyperlinks.

Fix regex so that context lines (from -C option) are still hyperlinked.

Also add a case so that any non-matching lines are still output raw.
@kovidgoyal kovidgoyal merged commit 512dccd into kovidgoyal:master Jun 24, 2021
@allemangD
Copy link
Contributor Author

🙏 Thanks!

@allemangD allemangD deleted the ripgrep-context branch June 24, 2021 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants