commit 5c3644ef2e24ca38c24bbb4c93ca5ce2075c9320 parent c996f9988157d1e41140e95ebb7ada929b116bbc Author: Samuel Dionne-Riel <samuel@dionne-riel.com> Date: Sun, 23 Jan 2022 01:36:21 -0500 saturn: Also include DATA_HOME > $XDG_DATA_DIRS defines the preference-ordered set of base > directories to search for data files in addition to the > $XDG_DATA_HOME base directory. The directories in > $XDG_DATA_DIRS should be seperated with a colon ':'. *in addition to the DATA_HOME base directory*. Diffstat:
| M | saturn/main.fnl | | | 28 | +++++++++++++++++++++++++++- |
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/saturn/main.fnl b/saturn/main.fnl @@ -94,7 +94,12 @@ (local path { :absolute? (fn [str] (= (str:sub 1 1) "/")) + :concat (fn [...] (table.concat [...] "/")) }) +(local search-path { + :concat (fn [...] (table.concat [...] ":")) + }) + (local Gtk lgi.Gtk) (local GdkPixbuf lgi.GdkPixbuf) @@ -154,9 +159,30 @@ (tset vals "IconImage" (find-icon vals.Icon))) vals)) +(fn current-user-home [] + "Returns current user's home directory." + (-> (posix.unistd.getuid) + (posix.pwd.getpwuid) + (. :pw_dir))) + +(fn xdg-data-home [] + "Provides XDG_DATA_HOME or its default fallback value" + (local data-home (os.getenv "XDG_DATA_HOME")) + (if data-home + data-home + (path.concat (current-user-home) ".local/share/"))) + +(fn xdg-data-dirs [] + "Provides all data-dirs as a colon-separated string." + ;; Expected to be used with gmatch as a generator. + (search-path.concat + (xdg-data-home) + (os.getenv "XDG_DATA_DIRS") + )) + (fn all-apps [] (var apps-table {}) - (each [path (string.gmatch (os.getenv "XDG_DATA_DIRS") "[^:]*")] + (each [path (string.gmatch (xdg-data-dirs) "[^:]*")] (let [apps (.. path "/applications/")] (when (lfs.attributes apps) (each [f (lfs.dir apps)]