@@ -21,8 +21,8 @@ const std::vector<std::string> Config::CONFIG_DIRS = {
21
21
22
22
const char *Config::CONFIG_PATH_ENV = " WAYBAR_CONFIG_DIR" ;
23
23
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) {
26
26
fs::path path;
27
27
28
28
if (!filename.empty ()) {
@@ -33,33 +33,35 @@ std::optional<std::string> Config::tryExpandPath(const std::string &base,
33
33
34
34
spdlog::debug (" Try expanding: {}" , path.string ());
35
35
36
+ std::vector<std::string> results;
36
37
wordexp_t p;
37
38
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
+ }
43
44
}
44
45
wordfree (&p);
45
46
}
46
- return std::nullopt;
47
+
48
+ return results;
47
49
}
48
50
49
51
std::optional<std::string> Config::findConfigPath (const std::vector<std::string> &names,
50
52
const std::vector<std::string> &dirs) {
51
53
if (const char *dir = std::getenv (Config::CONFIG_PATH_ENV)) {
52
54
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 () ;
55
57
}
56
58
}
57
59
}
58
60
59
61
for (const auto &dir : dirs) {
60
62
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 () ;
63
65
}
64
66
}
65
67
}
@@ -92,11 +94,15 @@ void Config::resolveConfigIncludes(Json::Value &config, int depth) {
92
94
if (includes.isArray ()) {
93
95
for (const auto &include : includes) {
94
96
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
+ }
96
100
}
97
101
} else if (includes.isString ()) {
98
102
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
+ }
100
106
}
101
107
}
102
108
0 commit comments