Files
flatpak/profile/flatpak.fish
Martin Kühl 16707a1937 profile.d: Only add new directories to XDG_DATA_DIRS in fish
Previously in a0505f52d9
the profile script was modified to preserve XDG_DATA_DIRS.
This had the side-effect of making the script not idempotent,
adding duplicate entries for every installation every time it's sourced.

On my current system  that results in this value:

    /home/mkhl/.local/share/flatpak/exports/share /var/lib/flatpak/exports/share /home/mkhl/.local/share/flatpak/exports/share /var/lib/flatpak/exports/share /usr/local/share /usr/share

which in turn has the side-effect of the GNOME search settings showing two entries
for every application installed via flatpak.

This change makes the script check that an entry is new before adding it.
It also uses `set -p` (short for `--prepend`) to add them.

N.B.
`set -p VAR val` is equivalent to `set VAR val $VAR`
`$var[-1..1]` reverses the order of elements
so after iterating the first element of `$installations`
becomes the first element of `$XDG_DATA_DIRS`
2022-12-04 11:43:30 -06:00

22 lines
633 B
Fish

if type -q flatpak
# Set XDG_DATA_DIRS to include Flatpak installations
set -x --path XDG_DATA_DIRS $XDG_DATA_DIRS
set -q XDG_DATA_DIRS[1]; or set XDG_DATA_DIRS /usr/local/share /usr/share
set -q XDG_DATA_HOME; or set -l XDG_DATA_HOME $HOME/.local/share
set -l installations $XDG_DATA_HOME/flatpak
begin
set -le G_MESSAGES_DEBUG
set -lx GIO_USE_VFS local
set installations $installations (flatpak --installations)
end
for dir in {$installations[-1..1]}/exports/share
if not contains $dir $XDG_DATA_DIRS
set -p XDG_DATA_DIRS $dir
end
end
end