From ac30733800b69dcb1589adcba6a42b20fa763e8f Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 30 Apr 2015 09:56:13 +0200 Subject: Search for the config file in $XDG_CONFIG_DIR/biboumi. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This environment variable points to the location the user expects to find every program’s config file, or if it isn’t set, ~/.config/biboumi (with a fallback to . if $HOME isn’t set). fix #2553 --- src/main.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 62a28a5..80462cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -68,7 +69,19 @@ int main(int ac, char** av) if (ac > 1) Config::filename = av[1]; else - Config::filename = "biboumi.cfg"; + { + const char* xdg_config_home = getenv("XDG_CONFIG_HOME"); + if (xdg_config_home) + Config::filename = std::string{xdg_config_home} + "/" "biboumi" "/" "biboumi.cfg"; + else + { + const char* home = getenv("HOME"); + if (home) + Config::filename = std::string{home} + "/" ".config" "/" "biboumi" "/" "biboumi.cfg"; + else + Config::filename = "biboumi.cfg"; + } + } Config::file_must_exist = true; std::cerr << "Using configuration file: " << Config::filename << std::endl; -- cgit v1.2.3