hypridle/src/helpers/MiscFunctions.cpp
martin a0037ac40c
config: add support for source option for additional config files (#144)
* feat: support `source` option for additional config files

* fix: prevent circular dependency
2025-05-02 17:27:53 +02:00

19 lines
No EOL
674 B
C++

#include <filesystem>
#include "MiscFunctions.hpp"
std::string absolutePath(const std::string& rawpath, const std::string& currentDir) {
std::filesystem::path path(rawpath);
// Handling where rawpath starts with '~'
if (!rawpath.empty() && rawpath[0] == '~') {
static const char* const ENVHOME = getenv("HOME");
path = std::filesystem::path(ENVHOME) / path.relative_path().string().substr(2);
}
// Handling e.g. ./, ../
if (path.is_relative())
return std::filesystem::weakly_canonical(std::filesystem::path(currentDir) / path);
else
return std::filesystem::weakly_canonical(path);
}