Dont change XDG_DATA_DIRS for child processes in fish shell integration
Fixes #4199
This commit is contained in:
parent
0f23edeec3
commit
35514e0cc3
@ -229,9 +229,8 @@ class Child:
|
|||||||
env['TERMINFO'] = tdir
|
env['TERMINFO'] = tdir
|
||||||
opts = fast_data_types.get_options()
|
opts = fast_data_types.get_options()
|
||||||
if opts.shell_integration != 'disabled':
|
if opts.shell_integration != 'disabled':
|
||||||
from .shell_integration import get_supported_shell_name
|
from .shell_integration import modify_shell_environ
|
||||||
if get_supported_shell_name(self.argv[0]):
|
modify_shell_environ(self.argv[0], opts, env)
|
||||||
env['KITTY_SHELL_INTEGRATION'] = opts.shell_integration
|
|
||||||
env = {k: v for k, v in env.items() if v is not DELETE_ENV_VAR}
|
env = {k: v for k, v in env.items() if v is not DELETE_ENV_VAR}
|
||||||
return env
|
return env
|
||||||
|
|
||||||
|
|||||||
@ -60,14 +60,20 @@ def setup_bash_integration(env: Dict[str, str]) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def setup_fish_integration(env: Dict[str, str]) -> None:
|
def setup_fish_integration(env: Dict[str, str]) -> None:
|
||||||
if 'XDG_DATA_DIRS' in env:
|
pass # this is handled in the fish env modifier
|
||||||
val = env.get('XDG_DATA_DIRS', '')
|
|
||||||
dirs = list(filter(None, val.split(os.pathsep)))
|
|
||||||
|
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:
|
else:
|
||||||
val = os.environ.get('XDG_DATA_DIRS', '')
|
|
||||||
dirs = list(filter(None, val.split(os.pathsep)))
|
dirs = list(filter(None, val.split(os.pathsep)))
|
||||||
if shell_integration_dir not in dirs:
|
|
||||||
dirs.insert(0, shell_integration_dir)
|
dirs.insert(0, shell_integration_dir)
|
||||||
|
env['KITTY_FISH_XDG_DATA_DIRS'] = val
|
||||||
env['XDG_DATA_DIRS'] = os.pathsep.join(dirs)
|
env['XDG_DATA_DIRS'] = os.pathsep.join(dirs)
|
||||||
|
|
||||||
|
|
||||||
@ -76,6 +82,9 @@ SUPPORTED_SHELLS = {
|
|||||||
'bash': setup_bash_integration,
|
'bash': setup_bash_integration,
|
||||||
'fish': setup_fish_integration,
|
'fish': setup_fish_integration,
|
||||||
}
|
}
|
||||||
|
ENV_MODIFIERS = {
|
||||||
|
'fish': setup_fish_env
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_supported_shell_name(path: str) -> Optional[str]:
|
def get_supported_shell_name(path: str) -> Optional[str]:
|
||||||
@ -85,10 +94,16 @@ def get_supported_shell_name(path: str) -> Optional[str]:
|
|||||||
return None
|
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())
|
q = set(opts.shell_integration.split())
|
||||||
if q & {'disabled', 'no-rc'}:
|
if q & {'disabled', 'no-rc'}:
|
||||||
return False
|
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])
|
shell = get_supported_shell_name(resolved_shell(opts)[0])
|
||||||
if shell is None:
|
if shell is None:
|
||||||
return False
|
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}')
|
log_error(f'Failed to setup shell integration for: {shell}')
|
||||||
return False
|
return False
|
||||||
return True
|
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
|
||||||
|
|||||||
@ -2,8 +2,14 @@
|
|||||||
|
|
||||||
function _ksi_main
|
function _ksi_main
|
||||||
test -z "$KITTY_SHELL_INTEGRATION" && return
|
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 --local _ksi (string split " " -- "$KITTY_SHELL_INTEGRATION")
|
||||||
set --erase KITTY_SHELL_INTEGRATION
|
set --erase KITTY_SHELL_INTEGRATION
|
||||||
|
set --erase KITTY_FISH_XDG_DATA_DIRS
|
||||||
|
|
||||||
function _ksi_osc
|
function _ksi_osc
|
||||||
printf "\e]%s\a" "$argv[1]"
|
printf "\e]%s\a" "$argv[1]"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user