From c8c6f8691f4aa84f4d798428af268319b898798f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 29 Nov 2021 12:41:25 +0530 Subject: [PATCH] Store the shell_integration option as a set --- kitty/child.py | 2 +- kitty/options/types.py | 2 +- kitty/options/utils.py | 14 +++++++------- kitty/shell_integration.py | 9 +++------ 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/kitty/child.py b/kitty/child.py index 4b8131d40..ce3f6cf63 100644 --- a/kitty/child.py +++ b/kitty/child.py @@ -231,7 +231,7 @@ class Child: env['TERMINFO'] = tdir env['KITTY_INSTALLATION_DIR'] = kitty_base_dir opts = fast_data_types.get_options() - if opts.shell_integration != 'disabled': + if 'disabled' not in opts.shell_integration: from .shell_integration import modify_shell_environ modify_shell_environ(self.argv[0], opts, env) env = {k: v for k, v in env.items() if v is not DELETE_ENV_VAR} diff --git a/kitty/options/types.py b/kitty/options/types.py index 9faea7b1b..a8f4880c4 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -547,7 +547,7 @@ class Options: selection_background: typing.Optional[kitty.fast_data_types.Color] = Color(255, 250, 205) selection_foreground: typing.Optional[kitty.fast_data_types.Color] = Color(0, 0, 0) shell: str = '.' - shell_integration: str = 'enabled' + shell_integration: typing.FrozenSet[str] = frozenset({'enabled'}) single_window_margin_width: FloatEdges = FloatEdges(left=-1.0, top=-1.0, right=-1.0, bottom=-1.0) startup_session: typing.Optional[str] = None strip_trailing_spaces: choices_for_strip_trailing_spaces = 'never' diff --git a/kitty/options/utils.py b/kitty/options/utils.py index fb8d3f647..4f85f493c 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -6,8 +6,8 @@ import os import re import sys from typing import ( - Any, Callable, Container, Dict, Iterable, Iterator, List, NamedTuple, - Optional, Sequence, Tuple, Union + Any, Callable, Container, Dict, FrozenSet, Iterable, Iterator, List, + NamedTuple, Optional, Sequence, Tuple, Union ) import kitty.fast_data_types as defines @@ -766,13 +766,13 @@ def watcher(val: str, current_val: Container[str]) -> Iterable[Tuple[str, str]]: yield val, val -def shell_integration(x: str) -> str: - s = {'enabled', 'disabled', 'no-rc', 'no-cursor', 'no-title', 'no-prompt-mark', 'no-complete'} - q = set(x.split()) +def shell_integration(x: str) -> FrozenSet[str]: + s = frozenset({'enabled', 'disabled', 'no-rc', 'no-cursor', 'no-title', 'no-prompt-mark', 'no-complete'}) + q = frozenset(x.lower().split()) if not q.issubset(s): log_error(f'Invalid shell integration options: {q - s}, ignoring') - return ' '.join(q & s) - return x + return q & s + return q def action_alias(val: str) -> Iterable[Tuple[str, str]]: diff --git a/kitty/shell_integration.py b/kitty/shell_integration.py index dcadc0157..c78a6fe1a 100644 --- a/kitty/shell_integration.py +++ b/kitty/shell_integration.py @@ -108,10 +108,7 @@ def get_supported_shell_name(path: str) -> Optional[str]: def shell_integration_allows_rc_modification(opts: Options) -> bool: - q = set(opts.shell_integration.split()) - if q & {'disabled', 'no-rc'}: - return False - return True + return not bool(opts.shell_integration & {'disabled', 'no-rc'}) def setup_shell_integration(opts: Options, env: Dict[str, str]) -> bool: @@ -133,9 +130,9 @@ def setup_shell_integration(opts: Options, env: Dict[str, str]) -> bool: def modify_shell_environ(argv0: str, opts: Options, env: Dict[str, str]) -> None: shell = get_supported_shell_name(argv0) - if shell is None or 'disabled' in set(opts.shell_integration.split()): + if shell is None or 'disabled' in opts.shell_integration: return - env['KITTY_SHELL_INTEGRATION'] = opts.shell_integration + env['KITTY_SHELL_INTEGRATION'] = ' '.join(opts.shell_integration) if not shell_integration_allows_rc_modification(opts): return f = ENV_MODIFIERS.get(shell)