From 8bea61cb99f766b7bc3c62897fa940cd92b20fb5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 23 Sep 2020 19:11:09 +0530 Subject: [PATCH] hyperlinked_grep: Ensure filename is always printed Fixes hyperlinks not working when a single file is searched --- docs/kittens/hyperlinked_grep.rst | 6 ++++++ kittens/hyperlinked_grep/main.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/kittens/hyperlinked_grep.rst b/docs/kittens/hyperlinked_grep.rst index f796229a7..bb75294cb 100644 --- a/docs/kittens/hyperlinked_grep.rst +++ b/docs/kittens/hyperlinked_grep.rst @@ -53,3 +53,9 @@ actions, :doc:`see here <../open_actions>`. Hopefully, someday this functionality will make it into some `upstream grep `_ program directly removing the need for this kitten. + + +.. note:: + While you can pass any of ripgrep's comand line options to the kitten and + they will be forwarded to rg, do not use options that change the output + formatting as the kitten works by parsing the output from ripgrep. diff --git a/kittens/hyperlinked_grep/main.py b/kittens/hyperlinked_grep/main.py index 45e9149a5..c840518c1 100644 --- a/kittens/hyperlinked_grep/main.py +++ b/kittens/hyperlinked_grep/main.py @@ -25,7 +25,7 @@ def write_hyperlink(write: Callable[[bytes], None], url: bytes, line: bytes, fra def main() -> None: if not sys.stdout.isatty() and '--pretty' not in sys.argv: os.execlp('rg', 'rg', *sys.argv[1:]) - cmdline = ['rg', '--pretty'] + sys.argv[1:] + cmdline = ['rg', '--pretty', '--with-filename'] + sys.argv[1:] p = subprocess.Popen(cmdline, stdout=subprocess.PIPE) assert p.stdout is not None write: Callable[[bytes], None] = cast(Callable[[bytes], None], sys.stdout.buffer.write)