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*.
phoen
Samuel Dionne-Riel 2022-01-23 01:36:21 -05:00 committed by Daniel Barlow
parent c996f99881
commit 5c3644ef2e
1 changed files with 27 additions and 1 deletions

View File

@ -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)]