From 69aead6d3d7574d8af2bf027cd201cdac35ed077 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 7 Jan 2025 08:21:53 +0530 Subject: [PATCH] query_terminal: Add support for reporting name of the OS the terminal emulator is running on Fixes #8201 --- docs/changelog.rst | 4 +++- kittens/query_terminal/main.py | 11 +++++++++++ kitty/conf/utils.py | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 016b817c1..32effce21 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -87,7 +87,7 @@ Detailed list of changes 0.39.0 [future] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- diff kitten: Automatically use dark/light color scheme based on the color scheme of the parent terminal. Can be controlled via the new :opt:`kitten-diff.color_scheme` option. Note that this is a **default behavior change** (:iss:`8170`) +- :doc:`diff kitten `: Automatically use dark/light color scheme based on the color scheme of the parent terminal. Can be controlled via the new :opt:`kitten-diff.color_scheme` option. Note that this is a **default behavior change** (:iss:`8170`) - Allow dynamically generating configuration by running an arbitrary program using the new :code:`geninclude` directive in :file:`kitty.conf` @@ -101,6 +101,8 @@ Detailed list of changes - diff kitten: Abort when run inside a terminal that does not support the kitty keyboard protocol (:iss:`8185`) +- :doc:`query kitten `: Add support for reporting name of the OS the terminal emulator is running on (:iss:`8201`) + - macOS: Allow using the Passwords app to autofill passwords via the Edit->Autofill menu mimicking other macOS applications (:pull:`8195`) - macOS: Add menu items to the Edit menu to clear the screen and scrollback diff --git a/kittens/query_terminal/main.py b/kittens/query_terminal/main.py index 2531ad5f0..aa313eae8 100644 --- a/kittens/query_terminal/main.py +++ b/kittens/query_terminal/main.py @@ -226,6 +226,17 @@ class ClipboardControl(Query): return ' '.join(opts.clipboard_control) +@query +class OSName(Query): + name: str = 'os_name' + help_text: str = 'The name of the OS the terminal is running on. Kitty supports values: linux, macos, bsd or unknown' + + @staticmethod + def get_result(opts: Options, window_id: int, os_window_id: int) -> str: + from kitty.conf.utils import os_name + return os_name() + + def get_result(name: str, window_id: int, os_window_id: int) -> Optional[str]: from kitty.fast_data_types import get_options q = all_queries.get(name) diff --git a/kitty/conf/utils.py b/kitty/conf/utils.py index 4470103f7..c68ea0194 100644 --- a/kitty/conf/utils.py +++ b/kitty/conf/utils.py @@ -14,6 +14,7 @@ from typing import ( Iterable, Iterator, List, + Literal, NamedTuple, Optional, Sequence, @@ -178,7 +179,7 @@ currently_parsing = CurrentlyParsing() @run_once -def os_name() -> str: +def os_name() -> Literal['macos', 'bsd', 'linux', 'unknown']: if is_macos: return 'macos' if 'bsd' in _plat: