| 26 | const char* Config::CONFIG_PATH_ENV = "WAYBAR_CONFIG_DIR"; |
| 27 | |
| 28 | std::vector<std::string> Config::tryExpandPath(const std::string& base, |
| 29 | const std::string& filename) { |
| 30 | fs::path path; |
| 31 | |
| 32 | if (!filename.empty()) { |
| 33 | path = fs::path(base) / fs::path(filename); |
| 34 | } else { |
| 35 | path = fs::path(base); |
| 36 | } |
| 37 | |
| 38 | spdlog::debug("Try expanding: {}", path.string()); |
| 39 | |
| 40 | std::vector<std::string> results; |
| 41 | #ifndef __OpenBSD__ |
| 42 | wordexp_t p; |
| 43 | if (wordexp(path.c_str(), &p, 0) == 0) { |
| 44 | for (size_t i = 0; i < p.we_wordc; i++) { |
| 45 | if (access(p.we_wordv[i], F_OK) == 0) { |
| 46 | results.emplace_back(p.we_wordv[i]); |
| 47 | spdlog::debug("Found config file: {}", p.we_wordv[i]); |
| 48 | } |
| 49 | } |
| 50 | wordfree(&p); |
| 51 | } |
| 52 | #else |
| 53 | glob_t p; |
| 54 | if (glob(path.c_str(), 0, NULL, &p) == 0) { |
| 55 | for (size_t i = 0; i < p.gl_pathc; i++) { |
| 56 | if (access(p.gl_pathv[i], F_OK) == 0) { |
| 57 | results.emplace_back(p.gl_pathv[i]); |
| 58 | spdlog::debug("Found config file: {}", p.gl_pathv[i]); |
| 59 | } |
| 60 | } |
| 61 | globfree(&p); |
| 62 | } |
| 63 | #endif |
| 64 | |
| 65 | return results; |
| 66 | } |
| 67 | |
| 68 | std::optional<std::string> Config::findConfigPath(const std::vector<std::string>& names, |
| 69 | const std::vector<std::string>& dirs) { |