From 3488dafb5629ca9e74e3cf38f592ac37f45ae497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20K=C3=BChl?= Date: Mon, 5 Dec 2022 13:43:09 +0100 Subject: [PATCH] ensure XDG_DATA_DIRS contains unique entries after importing from the nix environment we currently concatenate the new and old values of XDG_DATA_DIRS, which means if the nix environment reused or recreated the old values they are now present twice. XDG_DATA_DIRS is specified to be a "set", and some software (GNOME for example) assume that its entries are unique. this change reconstructs XDG_DATA_DIRS by looping over the new and old entries and adding the new ones among them. it normalizes the entries by removing trailing slashes to make duplicate detection a bit easier. --- direnvrc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/direnvrc b/direnvrc index 6247940..4b81a49 100644 --- a/direnvrc +++ b/direnvrc @@ -113,7 +113,16 @@ _nix_import_env() { _nix_export_or_unset TMPDIR "$old_tmpdir" _nix_export_or_unset TEMP "$old_temp" _nix_export_or_unset TEMPDIR "$old_tempdir" - export XDG_DATA_DIRS=$XDG_DATA_DIRS${old_xdg_data_dirs:+":"}$old_xdg_data_dirs + local new_xdg_data_dirs=${XDG_DATA_DIRS:-} + export XDG_DATA_DIRS= + local IFS=: + for dir in $new_xdg_data_dirs${old_xdg_data_dirs:+:}$old_xdg_data_dirs; do + dir="${dir%/}" # remove trailing slashes + if [[ :$XDG_DATA_DIRS: = *:$dir:* ]]; then + continue # already present, skip + fi + XDG_DATA_DIRS="$XDG_DATA_DIRS${XDG_DATA_DIRS:+:}$dir" + done } _nix_strip_escape_path() {