File: xdg.ml

package info (click to toggle)
ocaml-dune 2.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 14,064 kB
  • sloc: ml: 70,777; lisp: 466; ansic: 241; sh: 209; makefile: 119; python: 38; cpp: 17; javascript: 6
file content (31 lines) | stat: -rw-r--r-- 753 bytes parent folder | download
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
let home =
  try Sys.getenv "HOME"
  with Not_found -> (
    try (Unix.getpwuid (Unix.getuid ())).Unix.pw_dir with
    | Unix.Unix_error _
    | Not_found ->
      if Sys.win32 then
        try Sys.getenv "AppData" with Not_found -> ""
      else
        "" )

let ( / ) = Filename.concat

let get env_var unix_default win32_default =
  try Sys.getenv env_var
  with Not_found ->
    if Sys.win32 then
      win32_default
    else
      unix_default

let cache_dir =
  get "XDG_CACHE_HOME" (home / ".cache") (home / "Local Settings" / "Cache")

let config_dir =
  get "XDG_CONFIG_HOME" (home / ".config") (home / "Local Settings")

let data_dir =
  get "XDG_DATA_HOME"
    (home / ".local" / "share")
    (try Sys.getenv "AppData" with Not_found -> "")