Allow specifying user vars with the launch command

This commit is contained in:
Kovid Goyal
2023-07-27 17:44:37 +05:30
parent 4c18cae3a0
commit 83f423dbb0
2 changed files with 18 additions and 2 deletions

View File

@@ -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:

View File

@@ -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