diff --git a/kitty/child.py b/kitty/child.py index 13fcaf2b8..7f568cab8 100644 --- a/kitty/child.py +++ b/kitty/child.py @@ -229,9 +229,8 @@ class Child: env['TERMINFO'] = tdir opts = fast_data_types.get_options() if opts.shell_integration != 'disabled': - from .shell_integration import get_supported_shell_name - if get_supported_shell_name(self.argv[0]): - env['KITTY_SHELL_INTEGRATION'] = 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} return env diff --git a/kitty/shell_integration.py b/kitty/shell_integration.py index 8ca8826b1..8efb85690 100644 --- a/kitty/shell_integration.py +++ b/kitty/shell_integration.py @@ -60,15 +60,21 @@ def setup_bash_integration(env: Dict[str, str]) -> None: def setup_fish_integration(env: Dict[str, str]) -> None: - if 'XDG_DATA_DIRS' in env: - val = env.get('XDG_DATA_DIRS', '') - dirs = list(filter(None, val.split(os.pathsep))) + pass # this is handled in the fish env modifier + + +def setup_fish_env(env: Dict[str, str]) -> None: + val = env.get('XDG_DATA_DIRS') + if val is None: + env['XDG_DATA_DIRS'] = shell_integration_dir + elif not val: + env['XDG_DATA_DIRS'] = shell_integration_dir + env['KITTY_FISH_XDG_DATA_DIRS'] = '' else: - val = os.environ.get('XDG_DATA_DIRS', '') dirs = list(filter(None, val.split(os.pathsep))) - if shell_integration_dir not in dirs: dirs.insert(0, shell_integration_dir) - env['XDG_DATA_DIRS'] = os.pathsep.join(dirs) + env['KITTY_FISH_XDG_DATA_DIRS'] = val + env['XDG_DATA_DIRS'] = os.pathsep.join(dirs) SUPPORTED_SHELLS = { @@ -76,6 +82,9 @@ SUPPORTED_SHELLS = { 'bash': setup_bash_integration, 'fish': setup_fish_integration, } +ENV_MODIFIERS = { + 'fish': setup_fish_env +} def get_supported_shell_name(path: str) -> Optional[str]: @@ -85,10 +94,16 @@ def get_supported_shell_name(path: str) -> Optional[str]: return None -def setup_shell_integration(opts: Options, env: Dict[str, str]) -> bool: +def shell_integration_allows_rc_modification(opts: Options) -> bool: q = set(opts.shell_integration.split()) if q & {'disabled', 'no-rc'}: return False + return True + + +def setup_shell_integration(opts: Options, env: Dict[str, str]) -> bool: + if not shell_integration_allows_rc_modification(opts): + return False shell = get_supported_shell_name(resolved_shell(opts)[0]) if shell is None: return False @@ -101,3 +116,16 @@ def setup_shell_integration(opts: Options, env: Dict[str, str]) -> bool: log_error(f'Failed to setup shell integration for: {shell}') return False return True + + +def modify_shell_environ(argv0: str, opts: Options, env: Dict[str, str]) -> bool: + if not shell_integration_allows_rc_modification(opts): + return False + shell = get_supported_shell_name(argv0) + if shell is None: + return False + f = ENV_MODIFIERS.get(shell) + if f is not None: + f(env) + env['KITTY_SHELL_INTEGRATION'] = opts.shell_integration + return True diff --git a/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish b/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish index 0891f23e6..7d9f0f2b3 100644 --- a/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish +++ b/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish @@ -2,8 +2,14 @@ function _ksi_main test -z "$KITTY_SHELL_INTEGRATION" && return + if set -q KITTY_FISH_XDG_DATA_DIRS + set --export XDG_DATA_DIRS "$KITTY_FISH_XDG_DATA_DIRS" + else + set --erase XDG_DATA_DIRS + end set --local _ksi (string split " " -- "$KITTY_SHELL_INTEGRATION") set --erase KITTY_SHELL_INTEGRATION + set --erase KITTY_FISH_XDG_DATA_DIRS function _ksi_osc printf "\e]%s\a" "$argv[1]"