diff --git a/kitty/rc/base.py b/kitty/rc/base.py index 0ffd8bfeb..7d5b38282 100644 --- a/kitty/rc/base.py +++ b/kitty/rc/base.py @@ -91,7 +91,7 @@ MATCH_WINDOW_OPTION = '''\ --match -m The window to match. Match specifications are of the form: :italic:`field:query`. Where :italic:`field` can be one of: :code:`id`, :code:`title`, :code:`pid`, :code:`cwd`, :code:`cmdline`, :code:`num`, -:code:`env`, :code:`var`, :code:`state`, :code:`neighbor`, and :code:`recent`. +:code:`env`, :code:`var`, :code:`state`, :code:`neighbor`, :code:`session` and :code:`recent`. :italic:`query` is the expression to match. Expressions can be either a number or a regular expression, and can be :ref:`combined using Boolean operators `. @@ -112,6 +112,9 @@ active window, one being the previously active window and so on. The field :code:`neighbor` refers to a neighbor of the active window in the specified direction, which can be: :code:`left`, :code:`right`, :code:`top` or :code:`bottom`. +The field :code:`session` matches windows that were created in the specified session. +Use the expression :code:`^$` to match windows that were not created in a session. + When using the :code:`env` field to match on environment variables, you can specify only the environment variable name or a name and value, for example, :code:`env:MY_ENV_VAR=2`. @@ -135,7 +138,7 @@ MATCH_TAB_OPTION = '''\ --match -m The tab to match. Match specifications are of the form: :italic:`field:query`. Where :italic:`field` can be one of: :code:`id`, :code:`index`, :code:`title`, :code:`window_id`, :code:`window_title`, -:code:`pid`, :code:`cwd`, :code:`cmdline` :code:`env`, :code:`var`, :code:`state` and :code:`recent`. +:code:`pid`, :code:`cwd`, :code:`cmdline` :code:`env`, :code:`var`, :code:`state`, :code:`session` and :code:`recent`. :italic:`query` is the expression to match. Expressions can be either a number or a regular expression, and can be :ref:`combined using Boolean operators `. @@ -155,6 +158,9 @@ The :code:`index` number is used to match the nth tab in the currently active OS The :code:`recent` number matches recently active tabs in the currently active OS window, with zero being the currently active tab, one the previously active tab and so on. +The field :code:`session` matches tabs that were created in the specified session. +Use the expression :code:`^$` to match tabs that were not created in a session. + When using the :code:`env` field to match on environment variables, you can specify only the environment variable name or a name and value, for example, :code:`env:MY_ENV_VAR=2`. Tabs containing any window with the specified environment variables are matched. Similarly, :code:`var` matches tabs containing any window with the specified user variable. diff --git a/kitty/tabs.py b/kitty/tabs.py index 0fad3205f..5941a10b0 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -956,6 +956,8 @@ class Tab: # {{{ if query == 'parent_focused': return active_tab_manager is not None and self.tab_manager_ref() is active_tab_manager and self.os_window_id == last_focused_os_window_id() return False + if field == 'session': + return re.search(query, self.created_in_session_name) is not None return False def __iter__(self) -> Iterator[Window]: diff --git a/kitty/window.py b/kitty/window.py index 93470627f..f7a94f1ea 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -909,6 +909,8 @@ class Window: if pat.search(x) is not None: return True return False + if field == 'session': + return pat.search(self.created_in_session_name) is not None return False def matches_query(self, field: str, query: str, active_tab: TabType | None = None, self_window: Optional['Window'] = None) -> bool: