~singpolyma/biboumi

ac30733800b69dcb1589adcba6a42b20fa763e8f — Emmanuel Gil Peyrot 8 years ago a8225dc
Search for the config file in $XDG_CONFIG_DIR/biboumi.

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
1 files changed, 14 insertions(+), 1 deletions(-)

M src/main.cpp
M src/main.cpp => src/main.cpp +14 -1
@@ 8,6 8,7 @@
#include <iostream>
#include <memory>
#include <atomic>
#include <cstdlib>

#include <signal.h>



@@ 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;