mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-21 03:27:55 +03:00
Merge branch 'kitten-hyperlink-grep' of https://github.com/page-down/kitty
This commit is contained in:
commit
ff6d2e3c10
@ -67,7 +67,7 @@ the need for this kitten.
|
||||
output formatting as the kitten works by parsing the output from ripgrep.
|
||||
The unsupported options are: :code:`--context-separator`,
|
||||
:code:`--field-context-separator`, :code:`--field-match-separator`,
|
||||
:code:`--json`, :code:`-I --no-filename`, :code:`--no-heading`,
|
||||
:code:`-0 --null`, :code:`--null-data`, :code:`--path-separator`.
|
||||
If you specify options via configuration file, then any changes to the
|
||||
default output format will not be supported, not just the ones listed above.
|
||||
:code:`--json`, :code:`-I --no-filename`, :code:`-0 --null`,
|
||||
:code:`--null-data`, :code:`--path-separator`. If you specify options via
|
||||
configuration file, then any changes to the default output format will not be
|
||||
supported, not just the ones listed.
|
||||
|
@ -116,9 +116,6 @@ def main() -> None:
|
||||
raise SystemExit('Could not find the rg executable in your PATH. Is ripgrep installed?')
|
||||
assert p.stdout is not None
|
||||
|
||||
def get_quoted_path(x: bytes) -> bytes:
|
||||
return quote_from_bytes(os.path.abspath(x)).encode('utf-8')
|
||||
|
||||
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\\\\')
|
||||
@ -132,6 +129,9 @@ def get_quoted_path(x: bytes) -> bytes:
|
||||
in_result: bytes = b''
|
||||
hostname = get_hostname().encode('utf-8')
|
||||
|
||||
def get_quoted_url(file_path: bytes) -> bytes:
|
||||
return b'file://' + hostname + quote_from_bytes(os.path.abspath(file_path)).encode('utf-8')
|
||||
|
||||
try:
|
||||
for line in p.stdout:
|
||||
line = osc_pat.sub(b'', line) # remove any existing hyperlinks
|
||||
@ -158,20 +158,20 @@ def get_quoted_path(x: bytes) -> bytes:
|
||||
elif args.count or args.count_matches:
|
||||
m = path_with_count_pat.match(clean_line)
|
||||
if m is not None and link_file_headers:
|
||||
write_hyperlink(write, b'file://' + hostname + get_quoted_path(m.group(1)), line)
|
||||
write_hyperlink(write, get_quoted_url(m.group(1)), line)
|
||||
continue
|
||||
elif args.files or args.files_with_matches or args.files_without_match:
|
||||
if link_file_headers:
|
||||
write_hyperlink(write, get_quoted_path(clean_line), line)
|
||||
write_hyperlink(write, get_quoted_url(clean_line), line)
|
||||
continue
|
||||
elif args.vimgrep or args.no_heading:
|
||||
# When the vimgrep option is present, it will take precedence.
|
||||
m = vimgrep_pat.match(clean_line) if args.vimgrep else path_with_linenum_pat.match(clean_line)
|
||||
if m is not None and (link_file_headers or link_matching_lines):
|
||||
write_hyperlink(write, b'file://' + hostname + get_quoted_path(m.group(1)), line, frag=m.group(2))
|
||||
write_hyperlink(write, get_quoted_url(m.group(1)), line, frag=m.group(2))
|
||||
continue
|
||||
else:
|
||||
in_result = b'file://' + hostname + get_quoted_path(clean_line)
|
||||
in_result = get_quoted_url(clean_line)
|
||||
if link_file_headers:
|
||||
write_hyperlink(write, in_result, line)
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user