cppscripts/helpers.cpp

42 lines
708 B
C++

#include "helpers.hpp"
#include <cstdlib>
#include <string>
#include <string_view>
namespace helpers
{
std::string get_env(const std::string_view name)
{
const char *env{std::getenv(name.data())}; // NOLINT(concurrency-mt-unsafe)
if (env != nullptr)
{
return env;
}
return {};
}
std::string get_config_file_path(const std::string_view filename)
{
auto path{helpers::get_env("XDG_CONFIG_HOME")};
if (path.empty())
{
path = helpers::get_env("HOME");
if (!path.empty())
{
path += "/.config";
}
}
if (!path.empty())
{
path += "/";
}
path += filename;
return path;
}
} // namespace helpers