@@ -21,8 +21,8 @@ const std::vector<std::string> Config::CONFIG_DIRS = {
2121
2222const char *Config::CONFIG_PATH_ENV = " WAYBAR_CONFIG_DIR" ;
2323
24- std::optional <std::string> Config::tryExpandPath (const std::string &base,
25- const std::string &filename) {
24+ std::vector <std::string> Config::tryExpandPath (const std::string &base,
25+ const std::string &filename) {
2626 fs::path path;
2727
2828 if (!filename.empty ()) {
@@ -33,33 +33,35 @@ std::optional<std::string> Config::tryExpandPath(const std::string &base,
3333
3434 spdlog::debug (" Try expanding: {}" , path.string ());
3535
36+ std::vector<std::string> results;
3637 wordexp_t p;
3738 if (wordexp (path.c_str (), &p, 0 ) == 0 ) {
38- if ( access (*p. we_wordv , F_OK) == 0 ) {
39- std::string result = * p.we_wordv ;
40- wordfree (&p );
41- spdlog::debug (" Found config file: {}" , path. string () );
42- return result;
39+ for ( size_t i = 0 ; i < p. we_wordc ; i++ ) {
40+ if ( access ( p.we_wordv [i], F_OK) == 0 ) {
41+ results. emplace_back (p. we_wordv [i] );
42+ spdlog::debug (" Found config file: {}" , p. we_wordv [i] );
43+ }
4344 }
4445 wordfree (&p);
4546 }
46- return std::nullopt ;
47+
48+ return results;
4749}
4850
4951std::optional<std::string> Config::findConfigPath (const std::vector<std::string> &names,
5052 const std::vector<std::string> &dirs) {
5153 if (const char *dir = std::getenv (Config::CONFIG_PATH_ENV)) {
5254 for (const auto &name : names) {
53- if (auto res = tryExpandPath (dir, name); res) {
54- return res;
55+ if (auto res = tryExpandPath (dir, name); ! res. empty () ) {
56+ return res. front () ;
5557 }
5658 }
5759 }
5860
5961 for (const auto &dir : dirs) {
6062 for (const auto &name : names) {
61- if (auto res = tryExpandPath (dir, name); res) {
62- return res;
63+ if (auto res = tryExpandPath (dir, name); ! res. empty () ) {
64+ return res. front () ;
6365 }
6466 }
6567 }
@@ -92,11 +94,15 @@ void Config::resolveConfigIncludes(Json::Value &config, int depth) {
9294 if (includes.isArray ()) {
9395 for (const auto &include : includes) {
9496 spdlog::info (" Including resource file: {}" , include.asString ());
95- setupConfig (config, tryExpandPath (include.asString (), " " ).value_or (" " ), ++depth);
97+ for (const auto &match : tryExpandPath (include.asString (), " " )) {
98+ setupConfig (config, match, depth + 1 );
99+ }
96100 }
97101 } else if (includes.isString ()) {
98102 spdlog::info (" Including resource file: {}" , includes.asString ());
99- setupConfig (config, tryExpandPath (includes.asString (), " " ).value_or (" " ), ++depth);
103+ for (const auto &match : tryExpandPath (includes.asString (), " " )) {
104+ setupConfig (config, match, depth + 1 );
105+ }
100106 }
101107}
102108
0 commit comments