aboutsummaryrefslogtreecommitdiff
path: root/module/xdg
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-08-24 00:13:58 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-08-24 00:13:58 +0200
commit549cf99065e36ab7f2310d30119346ff123665dc (patch)
tree8c3d23e8df5c325e66da347feff6512a8cf4310f /module/xdg
parentMove html modules under calp. (diff)
downloadcalp-549cf99065e36ab7f2310d30119346ff123665dc.tar.gz
calp-549cf99065e36ab7f2310d30119346ff123665dc.tar.xz
Replace (directories) with general (xdg basedir).
Diffstat (limited to 'module/xdg')
-rw-r--r--module/xdg/basedir.scm61
1 files changed, 61 insertions, 0 deletions
diff --git a/module/xdg/basedir.scm b/module/xdg/basedir.scm
new file mode 100644
index 00000000..e734500e
--- /dev/null
+++ b/module/xdg/basedir.scm
@@ -0,0 +1,61 @@
+;;; Commentary:
+;;; https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
+;;; Code:
+
+(define-module (xdg basedir)
+ :export (sysconfdir runtime-dir
+ data-home config-home cache-home
+ data-dirs config-dirs))
+
+;;; XDG_DATA_HOME
+;;; $HOME/.local/share
+(define (data-home)
+ (or (getenv "XDG_DATA_HOME")
+ (string-append (getenv "HOME") "/.local/share")))
+
+;;; XDG_CONFIG_HOME
+;;; $HOME/.config
+(define (config-home)
+ (or (getenv "XDG_CONFIG_HOME")
+ (string-append (getenv "HOME") "/.config")))
+
+;;; XDG_DATA_DIRS
+;;; colon (:) sepparated, in addition to XDG_DATA_HOME
+;;; /usr/local/share/:/usr/share/
+(define (data-dirs)
+ (let ((str (getenv "XDG_DATA_DIRS")))
+ (if str
+ (string-split str #\:)
+ '("/usr/local/share" "/usr/share"))))
+
+;;; sysconfdir
+;;; /etc
+;;; Techincly not part of the standard, but it's mentioned
+(define (sysconfdir)
+ (or (getenv "sysconfdir")
+ "/etc"))
+
+
+;;; XDG_CONFIG_DIRS
+;;; colon (:) separated, in adddition to XDG_CONFIG_HOME
+;;; /etc/xdg
+(define (config-dirs)
+ (let ((str (getenv "XDG_CONFIG_DIRS")))
+ (if str
+ (string-split str #\:)
+ (list (string-append sysconfdir "/xdg")))))
+
+;;; XDG_CACHE_HOME
+;;; $HOME/.cache
+(define (cache-home)
+ (or (getenv "XDG_CACHE_HOME")
+ (string-append (getenv "HOME") "/.cache")))
+
+;;; XDG_RUNTIME_DIR
+;;; Default to /tmp or /tmp/$(uid), and raise a warning
+(define (runtime-dir)
+ (or (getenv "XDG_RUNTIME_DIR")
+ (begin
+ (display "WARNING: XDG_RUNTIME_DIR unset, defaulting to /tmp\n"
+ (current-error-port))
+ "/tmp")))