Allow users to modify XDG_DATA_DIRS in the fish rc files

The only downside of this new technique is that it is no
longer possible to set XDG_DATA_DIRS to an empty var in kitty.conf
Since an empty XDG_DATA_DIRS breaks lots fo things, I dont think that
is a big concern.
This commit is contained in:
Kovid Goyal 2021-11-07 18:59:50 +05:30
parent 6fa0a21b3c
commit b5e8b5a124
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 14 additions and 10 deletions

View File

@ -65,15 +65,12 @@ def setup_fish_integration(env: Dict[str, str]) -> None:
def setup_fish_env(env: Dict[str, str]) -> None:
val = env.get('XDG_DATA_DIRS')
if val is None:
env['KITTY_FISH_XDG_DATA_DIR'] = shell_integration_dir
if not val:
env['XDG_DATA_DIRS'] = shell_integration_dir
elif not val:
env['XDG_DATA_DIRS'] = shell_integration_dir
env['KITTY_FISH_XDG_DATA_DIRS'] = ''
else:
dirs = list(filter(None, val.split(os.pathsep)))
dirs.insert(0, shell_integration_dir)
env['KITTY_FISH_XDG_DATA_DIRS'] = val
env['XDG_DATA_DIRS'] = os.pathsep.join(dirs)

View File

@ -2,14 +2,21 @@
function _ksi_main
test -z "$KITTY_SHELL_INTEGRATION" && return
if set -q KITTY_FISH_XDG_DATA_DIRS
set --global --export XDG_DATA_DIRS "$KITTY_FISH_XDG_DATA_DIRS"
else
set --erase XDG_DATA_DIRS
if set -q XDG_DATA_DIRS
set --global --export --path XDG_DATA_DIRS "$XDG_DATA_DIRS"
if set -q KITTY_FISH_XDG_DATA_DIR
if set -l index (contains -i "$KITTY_FISH_XDG_DATA_DIR" $XDG_DATA_DIRS)
set --erase --global XDG_DATA_DIRS[$index]
test -z "$XDG_DATA_DIRS" && set --erase --global XDG_DATA_DIRS
end
end
if set -q XDG_DATA_DIRS
set --global --export --unpath XDG_DATA_DIRS "$XDG_DATA_DIRS"
end
end
set --local _ksi (string split " " -- "$KITTY_SHELL_INTEGRATION")
set --erase KITTY_SHELL_INTEGRATION
set --erase KITTY_FISH_XDG_DATA_DIRS
set --erase KITTY_FISH_XDG_DATA_DIR
function _ksi_osc
printf "\e]%s\a" "$argv[1]"