From bb3a8453e07370c3f291d28cc1066202991a020b Mon Sep 17 00:00:00 2001 From: David Allemang Date: Thu, 24 Jun 2021 11:04:35 -0400 Subject: [PATCH] Make hyperlinked_grep kitten respect context 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. --- kittens/hyperlinked_grep/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kittens/hyperlinked_grep/main.py b/kittens/hyperlinked_grep/main.py index db9c7749e..39572061d 100644 --- a/kittens/hyperlinked_grep/main.py +++ b/kittens/hyperlinked_grep/main.py @@ -29,7 +29,7 @@ def main() -> None: write: Callable[[bytes], None] = cast(Callable[[bytes], None], sys.stdout.buffer.write) sgr_pat = re.compile(br'\x1b\[.*?m') osc_pat = re.compile(b'\x1b\\].*?\x1b\\\\') - num_pat = re.compile(b'^(\\d+):') + num_pat = re.compile(b'^(\\d+)[:\\-]') in_result: bytes = b'' hostname = socket.gethostname().encode('utf-8') @@ -46,6 +46,8 @@ def main() -> None: m = num_pat.match(clean_line) if m is not None: write_hyperlink(write, in_result, line, frag=m.group(1)) + else: + write(line) else: if line.strip(): path = quote_from_bytes(os.path.abspath(clean_line)).encode('utf-8')