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.
|
output formatting as the kitten works by parsing the output from ripgrep.
|
||||||
The unsupported options are: :code:`--context-separator`,
|
The unsupported options are: :code:`--context-separator`,
|
||||||
:code:`--field-context-separator`, :code:`--field-match-separator`,
|
:code:`--field-context-separator`, :code:`--field-match-separator`,
|
||||||
:code:`--json`, :code:`-I --no-filename`, :code:`--no-heading`,
|
:code:`--json`, :code:`-I --no-filename`, :code:`-0 --null`,
|
||||||
:code:`-0 --null`, :code:`--null-data`, :code:`--path-separator`.
|
:code:`--null-data`, :code:`--path-separator`. If you specify options via
|
||||||
If you specify options via configuration file, then any changes to the
|
configuration file, then any changes to the default output format will not be
|
||||||
default output format will not be supported, not just the ones listed above.
|
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?')
|
raise SystemExit('Could not find the rg executable in your PATH. Is ripgrep installed?')
|
||||||
assert p.stdout is not None
|
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)
|
write: Callable[[bytes], None] = cast(Callable[[bytes], None], sys.stdout.buffer.write)
|
||||||
sgr_pat = re.compile(br'\x1b\[.*?m')
|
sgr_pat = re.compile(br'\x1b\[.*?m')
|
||||||
osc_pat = re.compile(b'\x1b\\].*?\x1b\\\\')
|
osc_pat = re.compile(b'\x1b\\].*?\x1b\\\\')
|
||||||
@ -132,6 +129,9 @@ def main() -> None:
|
|||||||
in_result: bytes = b''
|
in_result: bytes = b''
|
||||||
hostname = get_hostname().encode('utf-8')
|
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:
|
try:
|
||||||
for line in p.stdout:
|
for line in p.stdout:
|
||||||
line = osc_pat.sub(b'', line) # remove any existing hyperlinks
|
line = osc_pat.sub(b'', line) # remove any existing hyperlinks
|
||||||
@ -158,20 +158,20 @@ def main() -> None:
|
|||||||
elif args.count or args.count_matches:
|
elif args.count or args.count_matches:
|
||||||
m = path_with_count_pat.match(clean_line)
|
m = path_with_count_pat.match(clean_line)
|
||||||
if m is not None and link_file_headers:
|
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
|
continue
|
||||||
elif args.files or args.files_with_matches or args.files_without_match:
|
elif args.files or args.files_with_matches or args.files_without_match:
|
||||||
if link_file_headers:
|
if link_file_headers:
|
||||||
write_hyperlink(write, get_quoted_path(clean_line), line)
|
write_hyperlink(write, get_quoted_url(clean_line), line)
|
||||||
continue
|
continue
|
||||||
elif args.vimgrep or args.no_heading:
|
elif args.vimgrep or args.no_heading:
|
||||||
# When the vimgrep option is present, it will take precedence.
|
# 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)
|
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):
|
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
|
continue
|
||||||
else:
|
else:
|
||||||
in_result = b'file://' + hostname + get_quoted_path(clean_line)
|
in_result = get_quoted_url(clean_line)
|
||||||
if link_file_headers:
|
if link_file_headers:
|
||||||
write_hyperlink(write, in_result, line)
|
write_hyperlink(write, in_result, line)
|
||||||
continue
|
continue
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user