From 322a1547c217314b278acb9c8929378e9378bfb7 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Sun, 10 Mar 2024 22:17:20 +0100 Subject: Teach apps activation script to set XDG_DATA_DIRS This allows systemd to find units, and desktop environments to find application entries. --- guides/setups/operating-systems/apps-demo/activate | 33 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'guides/setups/operating-systems/apps-demo') diff --git a/guides/setups/operating-systems/apps-demo/activate b/guides/setups/operating-systems/apps-demo/activate index 434924a..fbf522c 100644 --- a/guides/setups/operating-systems/apps-demo/activate +++ b/guides/setups/operating-systems/apps-demo/activate @@ -1,12 +1,41 @@ # Hey Emacs; this is a -*- shell-script -*-. # Hopefully invoked by bash 🤞 -_apps_dir=$(dirname ${BASH_SOURCE}) +_apps_dir=$(realpath --no-symlinks $(dirname ${BASH_SOURCE})) _apps_PATH=$( shopt -s nullglob bins=( "${_apps_dir}"/*/bin ) IFS=: eval 'echo "${bins[*]}"' ) - export PATH=${_apps_PATH}:${PATH} + +_apps_XDG_DATA_DIRS=$( + shopt -s nullglob + # We could set globstar and let Bash loose, searching the depths + # of _apps_dir for + # **/{applications/*.desktop,systemd/user/*.service} + # but it seems like asking for trouble. Make some assumptions + # about where applications typically dump their XDG-related files. + datadirs=($( + { + for dkentry in "${_apps_dir}"/*/share/applications/*.desktop + do + echo ${dkentry%/applications/*.desktop} + done + for unit in "${_apps_dir}"/*/lib*/systemd/user/*.service + do + echo ${unit%/systemd/user/*.service} + done + } | sort -u + )) + IFS=: eval 'echo "${datadirs[*]}"' +) +export XDG_DATA_DIRS=$( + if test "${XDG_DATA_DIRS}" + then + echo "${_apps_XDG_DATA_DIRS}:${XDG_DATA_DIRS}" + else + echo "${_apps_XDG_DATA_DIRS}" + fi +) -- cgit v1.2.3