From 83f423dbb0bebfea4eeb894b1dae6517671dccee Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 27 Jul 2023 17:44:37 +0530 Subject: [PATCH] Allow specifying user vars with the launch command --- kitty/launch.py | 19 +++++++++++++++++-- kitty/rc/launch.py | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/kitty/launch.py b/kitty/launch.py index 8d818003d..c909c3794 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -107,6 +107,13 @@ times to set different environment variables. Syntax: :code:`name=value`. Using environment variable. +--var +type=list +User variables to set in the created window. Can be specified multiple +times to set different user variables. Syntax: :code:`name=value`. Using +:code:`name=` will set to empty string. + + --hold type=bool-set Keep the window open even after the command being executed exits, at a shell prompt. @@ -412,6 +419,12 @@ def apply_colors(window: Window, spec: Sequence[str]) -> None: patch_color_profiles(colors, profiles, True) +def parse_var(defn: Iterable[str]) -> Iterator[Tuple[str, str]]: + for item in defn: + a, sep, b = item.partition('=') + yield a, b + + class ForceWindowLaunch: def __init__(self) -> None: @@ -605,6 +618,9 @@ def _launch( new_window.set_logo(opts.logo, opts.logo_position or '', opts.logo_alpha) if opts.type == 'overlay-main': new_window.overlay_type = OverlayType.main + if opts.var: + for key, val in parse_var(opts.var): + new_window.user_vars[key] = val return new_window return None @@ -631,7 +647,7 @@ def launch( @run_once def clone_safe_opts() -> FrozenSet[str]: return frozenset(( - 'window_title', 'tab_title', 'type', 'keep_focus', 'cwd', 'env', 'hold', + 'window_title', 'tab_title', 'type', 'keep_focus', 'cwd', 'env', 'var', 'hold', 'location', 'os_window_class', 'os_window_name', 'os_window_title', 'os_window_state', 'logo', 'logo_position', 'logo_alpha', 'color', 'spacing', )) @@ -885,7 +901,6 @@ def clone_and_launch(msg: str, window: Window) -> None: patch_cmdline('env', entry, cmdline) c.opts.env = [] else: - try: cmdline = window.child.cmdline_of_pid(c.pid) except Exception: diff --git a/kitty/rc/launch.py b/kitty/rc/launch.py index e48a2877e..2d5f6d795 100644 --- a/kitty/rc/launch.py +++ b/kitty/rc/launch.py @@ -23,6 +23,7 @@ class Launch(RemoteCommand): window_title/str: Title for the new window cwd/str: Working directory for the new window env/list.str: List of environment variables of the form NAME=VALUE + var/list.str: List of user variables of the form NAME=VALUE tab_title/str: Title for the new tab type/choices.window.tab.os-window.overlay.overlay-main.background.clipboard.primary: The type of window to open keep_focus/bool: Boolean indicating whether the current window should retain focus or not