about summary refs log tree commit diff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-04-25T16·56+0200
committerEelco Dolstra <edolstra@gmail.com>2017-04-25T16·56+0200
commit5bd8795e1fa9255836fbbeab0a22f5038d92d53c (patch)
tree8df5a5f1c13b080f38e6a4e27f6ac64073133273 /src/libutil/util.cc
parent921a2aeb0537f34bc2b41e98e67a1c829321ee81 (diff)
nix repl: Use $XDG_DATA_HOME for the readline history
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 88a2f752c023..026e493514ea 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -441,6 +441,18 @@ Path getConfigDir()
 }
 
 
+Path getDataDir()
+{
+    Path dataDir = getEnv("XDG_DATA_HOME");
+    if (dataDir.empty()) {
+        Path homeDir = getEnv("HOME");
+        if (homeDir.empty()) throw Error("$XDG_DATA_HOME and $HOME are not set");
+        dataDir = homeDir + "/.local/share";
+    }
+    return dataDir;
+}
+
+
 Paths createDirs(const Path & path)
 {
     Paths created;