diff --git a/docs/changelog.rst b/docs/changelog.rst index 35284578e..b9f5f067f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -51,6 +51,7 @@ Detailed list of changes - Fix tab selection when closing a new tab not correct in some scenarios (:iss:`4987`) +- A new action :ac:`open_url` to open the specified URL (:pull:`5004`) 0.25.0 [2022-04-11] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/boss.py b/kitty/boss.py index 9979d99a3..8de17eb2b 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -1513,6 +1513,7 @@ class Boss: if tab: tab.set_active_window(window_id) + @ac('misc', 'Open the specified URL') def open_url(self, url: str, program: Optional[Union[str, List[str]]] = None, cwd: Optional[str] = None) -> None: if not url: return diff --git a/kitty/options/utils.py b/kitty/options/utils.py index 87916f39c..fdb5b45ee 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -91,6 +91,20 @@ def kitten_parse(func: str, rest: str) -> FuncArgsType: return func, [args[0]] + (to_cmdline(args[1]) if len(args) > 1 else []) +@func_with_args('open_url') +def open_url_parse(func: str, rest: str) -> FuncArgsType: + from urllib.parse import urlparse + url = '' + try: + url = python_string(rest) + tokens = urlparse(url) + if not all((tokens.scheme, tokens.netloc,)): + raise ValueError('Invalid URL') + except Exception: + log_error('Ignoring invalid URL string: ' + rest) + return func, (url,) + + @func_with_args('goto_tab') def goto_tab_parse(func: str, rest: str) -> FuncArgsType: args = (max(0, int(rest)), )