Make NETLOC avaialble to open action commandlines

This commit is contained in:
Kovid Goyal 2024-05-22 14:56:50 +05:30
parent b3ea6526e7
commit c0f820443b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 7 additions and 7 deletions

View File

@ -64,6 +64,9 @@ some special variables, documented below:
``FRAGMENT``
The fragment (unquoted), if any of the URL or the empty string.
``NETLOC``
The net location aka hostname (unquoted), if any of the URL or the empty string.
``URL_PATH``
The path, query and fragment portions of the URL, without any
unquoting.

View File

@ -69,7 +69,7 @@ def parse(lines: Iterable[str]) -> Iterator[OpenAction]:
entries.append((tuple(match_criteria), tuple(raw_actions)))
with to_cmdline_implementation.filter_env_vars(
'URL', 'FILE_PATH', 'FILE', 'FRAGMENT', 'URL_PATH',
'URL', 'FILE_PATH', 'FILE', 'FRAGMENT', 'URL_PATH', 'NETLOC',
EDITOR=shlex.join(get_editor()),
SHELL=resolved_shell(get_options())[0]
):
@ -164,6 +164,7 @@ def actions_for_url_from_list(url: str, actions: Iterable[OpenAction]) -> Iterat
return
path = unquote(purl.path)
up = purl.path
netloc = unquote(purl.netloc) if purl.netloc else ''
frag = ''
if purl.query:
up += f'?{purl.query}'
@ -181,6 +182,7 @@ def actions_for_url_from_list(url: str, actions: Iterable[OpenAction]) -> Iterat
'URL_PATH': up,
'FILE': posixpath.basename(path),
'FRAGMENT': frag,
'NETLOC': netloc,
}
def expand(x: Any) -> Any:
@ -236,7 +238,7 @@ def default_open_actions() -> Tuple[OpenAction, ...]:
# Open kitty HTML docs links
protocol kitty+doc
action show_kitty_doc $URL_PATH
'''.splitlines()))
'''.splitlines()))
@run_once

View File

@ -1073,11 +1073,6 @@ def open_url(self, url: str, hyperlink_id: int, cwd: Optional[str] = None) -> No
self.handle_remote_file(purl.netloc, unquote(purl.path))
return
url = urlunparse(purl._replace(netloc=''))
if purl.fragment and purl.fragment.startswith('-'):
# Dont allow fragments that startwith - as that can lead to arg
# injection
log_error('Ignoring fragment that starts with - in URL:', url)
url = urlunparse(purl._replace(fragment=''))
if opts.allow_hyperlinks & 0b10:
from kittens.tui.operations import styled
boss.choose(