summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@googlemail.com>2017-05-16 14:11:31 +0100
committerGitHub <noreply@github.com>2017-05-16 14:11:31 +0100
commit80aa02e7f97b345a7a3673e47a9993f2ddb31dc6 (patch)
tree5edf9142d132569c5cf8090eb415af4a452fefed
parente6827f7cc394b2e17df40c537fcdad07e1dfa172 (diff)
parenteb9721a804a7beff701e1aa6a3f0c049b7e53c71 (diff)
downloadNim-80aa02e7f97b345a7a3673e47a9993f2ddb31dc6.tar.gz
Merge pull request #5748 from J3RN/meet-xdg-base-directory-spec
Modified ospath's getConfigDir to meet XDG spec
-rw-r--r--lib/pure/ospaths.nim9
-rw-r--r--web/news/e031_version_0_16_2.rst4
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/pure/ospaths.nim b/lib/pure/ospaths.nim
index 7720fb2a6..fa5342fcf 100644
--- a/lib/pure/ospaths.nim
+++ b/lib/pure/ospaths.nim
@@ -516,7 +516,16 @@ when declared(getEnv) or defined(nimscript):
   proc getConfigDir*(): string {.rtl, extern: "nos$1",
     tags: [ReadEnvEffect, ReadIOEffect].} =
     ## Returns the config directory of the current user for applications.
+    ##
+    ## On non-Windows OSs, this proc conforms to the XDG Base Directory
+    ## spec. Thus, this proc returns the value of the XDG_CONFIG_DIR environment
+    ## variable if it is set, and returns the default configuration directory,
+    ## "~/.config/", otherwise.
+    ##
+    ## An OS-dependent trailing slash is always present at the end of the
+    ## returned string; `\\` on Windows and `/` on all other OSs.
     when defined(windows): return string(getEnv("APPDATA")) & "\\"
+    elif getEnv("XDG_CONFIG_DIR"): return string(getEnv("XDG_CONFIG_DIR")) & "/"
     else: return string(getEnv("HOME")) & "/.config/"
 
   proc getTempDir*(): string {.rtl, extern: "nos$1",
diff --git a/web/news/e031_version_0_16_2.rst b/web/news/e031_version_0_16_2.rst
index 4f49bd8d9..4e0784124 100644
--- a/web/news/e031_version_0_16_2.rst
+++ b/web/news/e031_version_0_16_2.rst
@@ -63,6 +63,10 @@ Changes affecting backwards compatibility
   compile-time value.
 - On posix, the results of `waitForExit`, `peekExitCode`, `execCmd` will return
   128 + signal number if the application terminates via signal.
+- ``ospaths.getConfigDir`` now conforms to the XDG Base Directory specification
+  on non-Windows OSs. It returns the value of the XDG_CONFIG_DIR environment
+  variable if it is set, and returns the default configuration directory,
+  "~/.config/", otherwise.
 
 Library Additions
 -----------------