diff --git a/docs/changelog.rst b/docs/changelog.rst index 2f5948dbc..55b84eed4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -13,6 +13,9 @@ To update |kitty|, :doc:`follow the instructions `. boundary rather than the end of the selection. To restore previous behavior use ``mouse_map right press ungrabbed mouse_selection move-end``. +- When opening hyperlinks, allow defining open actions for directories + (:pull:`3836`) + - Fix a bug in the implementation of the synchronized updates escape code that could cause incorrect parsing if either the pending buffer capacity or the pending timeout were exceeded (:iss:`3779`) diff --git a/docs/open_actions.rst b/docs/open_actions.rst index c557a453a..70b20588a 100644 --- a/docs/open_actions.rst +++ b/docs/open_actions.rst @@ -85,7 +85,7 @@ lines. The various available criteria are: :file:`mime.types` in the kitty configuration directory. Useful if your system MIME database does not have definitions you need. This file is in the standard format of one definition per line, like: ``text/plain rst - md``. + md``. Note that the MIME type for directories is ``inode/directory``. ``ext`` A comma separated list of file extensions, for example: ``jpeg, tar.gz`` diff --git a/kitty/guess_mime_type.py b/kitty/guess_mime_type.py index 4a2a3d0db..048036d29 100644 --- a/kitty/guess_mime_type.py +++ b/kitty/guess_mime_type.py @@ -28,8 +28,12 @@ def is_rc_file(path: str) -> bool: name = os.path.basename(path) return '.' not in name and name.endswith('rc') + def is_folder(path: str) -> bool: - return os.path.isdir(path) + with suppress(OSError): + return os.path.isdir(path) + return False + def initialize_mime_database() -> None: if hasattr(initialize_mime_database, 'inited'): @@ -43,7 +47,9 @@ def initialize_mime_database() -> None: init((local_defs,)) -def guess_type(path: str) -> Optional[str]: +def guess_type(path: str, allow_filesystem_access: bool = False) -> Optional[str]: + if allow_filesystem_access and is_folder(path): + return 'inode/directory' from mimetypes import guess_type as stdlib_guess_type initialize_mime_database() mt = None diff --git a/kitty/open_actions.py b/kitty/open_actions.py index acd144db1..eb398b0f0 100644 --- a/kitty/open_actions.py +++ b/kitty/open_actions.py @@ -76,7 +76,7 @@ def url_matches_criterion(purl: 'ParseResult', url: str, unquoted_path: str, mc: if mc.type == 'mime': import fnmatch - mt = guess_type(unquoted_path) + mt = guess_type(unquoted_path, allow_filesystem_access=True) if not mt: return False mt = mt.lower()