aboutsummaryrefslogtreecommitdiff
path: root/module/xdg/basedir.scm
blob: 664f58e32da58e6b6bb5fc93b9de47c7a3b705dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
;;; Commentary:
;;; https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
;;; Code:

(define-module (xdg basedir)
  :export (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
        (parse-path str)
        '("/usr/local/share" "/usr/share"))))

;;; 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")))