[PATCH] Avoid duplicating directories in the tail of $XDG_* envs
Example input: XDG_CONFIG_DIRS="/etc/xdg/rosa-xfce-config:/etc/xdg"
Output before this patch: XDG_CONFIG_DIRS="/etc/xdg/rosa-xfce-config:/etc/xdg:/etc/xdg"
But there is no need to duplicate /etc/xdg
in the tail.
Output after this patch: XDG_CONFIG_DIRS="/etc/xdg/rosa-xfce-config:/etc/xdg"
The scripts that sets XDG_CONFIG_DIRS: https://abf.io/soft/rosa-xfce-config/blob/04b69c389d/profile.d/10-rosa-xfce-config-xdg.sh
Tests for that script: https://abf.io/soft/rosa-xfce-config/blob/04b69c389d/profile.d/test_10-rosa-xfce-config-xdg.sh
I do not see why that my script must not append "/etc/xdg", so fixing startxfce4.
This case-esac code is compatible with POSIX shell (https://stackoverflow.com/a/2830416), but tested it only with bash.
Diff is bellow, git am
-able patch is attached.
0001-Avoid-duplicating-directories-in-the-tail-of-XDG_-en.patch
diff --git a/scripts/startxfce4.in b/scripts/startxfce4.in
index bf3201b6..b20a9cf4 100644
--- a/scripts/startxfce4.in
+++ b/scripts/startxfce4.in
@@ -72,7 +72,11 @@ then
XDG_DATA_DIRS="@_datadir_@:/usr/local/share:/usr/share"
fi
else
- XDG_DATA_DIRS="$XDG_DATA_DIRS:@_datadir_@"
+ # avoid duplicating @_datadir_@ if $XDG_DATA_DIRS already contains it
+ case "$XDG_DATA_DIRS" in
+ *:@_datadir_@ | @_datadir_@ ) : ;;
+ * ) XDG_DATA_DIRS="$XDG_DATA_DIRS:@_datadir_@" ;;
+ esac
fi
export XDG_DATA_DIRS
@@ -84,7 +88,11 @@ then
XDG_CONFIG_DIRS="/etc/xdg:@_sysconfdir_@/xdg"
fi
else
- XDG_CONFIG_DIRS="$XDG_CONFIG_DIRS:@_sysconfdir_@/xdg"
+ # avoid duplicating @_sysconfdir_@/xdg if $XDG_CONFIG_DIRS already contains it
+ case "$XDG_CONFIG_DIRS" in
+ *:@_sysconfdir_@/xdg | @_sysconfdir_@/xdg ) : ;;
+ * ) XDG_CONFIG_DIRS="$XDG_CONFIG_DIRS:@_sysconfdir_@/xdg" ;;
+ esac
fi
export XDG_CONFIG_DIRS