Skip to content

Commit

Permalink
path: return xdgConfigHome or home if config is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
fufexan committed Jul 8, 2024
1 parent e512fcd commit 21f2b93
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/path/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,23 @@ namespace Hyprutils::Path {
}

std::optional<std::string> findConfig(std::string programName) {
static const auto xdgConfigHome = getXdgConfigHome();
if (xdgConfigHome.has_value() && checkConfigExists(xdgConfigHome.value(), programName))
return xdgConfigHome;
bool xdgConfigHomeExists = false;
static const auto xdgConfigHome = getXdgConfigHome();
if (xdgConfigHome.has_value()) {
if (checkConfigExists(xdgConfigHome.value(), programName))
return std::optional<std::string>(xdgConfigHome.value() + "/hypr/" + programName + ".conf");
else
xdgConfigHomeExists = true;
}

static const auto home = getHome();
if (home.has_value() && checkConfigExists(home.value(), programName))
return home;
bool homeExists = false;
static const auto home = getHome();
if (home.has_value()) {
if (checkConfigExists(home.value(), programName))
return std::optional<std::string>(home.value() + "/hypr/" + programName + ".conf");
else
homeExists = true;
}

static const auto xdgConfigDirs = getXdgConfigDirs();
if (xdgConfigDirs.has_value()) {
Expand All @@ -61,6 +71,11 @@ namespace Hyprutils::Path {
if (checkConfigExists("/etc/xdg", programName))
return (std::optional<std::string>)"/etc/xdg";

return std::nullopt;
if (xdgConfigHomeExists)
return xdgConfigHome;
else if (homeExists)
return home;
else
return std::nullopt;
}
}

0 comments on commit 21f2b93

Please sign in to comment.