diff --git a/include/utils/env.hpp b/include/utils/env.hpp index da4311b0..8fcc4da3 100644 --- a/include/utils/env.hpp +++ b/include/utils/env.hpp @@ -5,8 +5,8 @@ POLYBAR_NS namespace env_util { - bool has(const char* var); - string get(const char* var, string fallback = ""); + bool has(const string& var); + string get(const string& var, string fallback = ""); } POLYBAR_NS_END diff --git a/include/utils/file.hpp b/include/utils/file.hpp index 840bc8fa..80436a8e 100644 --- a/include/utils/file.hpp +++ b/include/utils/file.hpp @@ -105,7 +105,7 @@ namespace file_util { string pick(const vector& filenames); string contents(const string& filename); bool is_fifo(const string& filename); - vector glob(const string& pattern); + vector glob(string pattern); template decltype(auto) make_file_descriptor(Args&&... args) { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bb85186e..ee9292c3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -149,7 +149,7 @@ target_compile_options(${PROJECT_NAME} PUBLIC # Create executable target: ipc messager {{{ if(BUILD_IPC_MSG) - make_executable(${PROJECT_NAME}-msg SOURCES ipc.cpp utils/file.cpp) + make_executable(${PROJECT_NAME}-msg SOURCES ipc.cpp utils/env.cpp utils/file.cpp) target_compile_options(${PROJECT_NAME}-msg PUBLIC $<$:$<$:-flto>>) endif() diff --git a/src/main.cpp b/src/main.cpp index 191042a0..9cb9ba0d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,19 +1,13 @@ -#include "common.hpp" #include "components/bar.hpp" #include "components/command_line.hpp" #include "components/config.hpp" #include "components/controller.hpp" #include "components/ipc.hpp" -#include "components/logger.hpp" #include "components/parser.hpp" #include "components/renderer.hpp" -#include "settings.hpp" #include "utils/env.hpp" -#include "utils/file.hpp" #include "utils/inotify.hpp" -#include "utils/io.hpp" #include "utils/process.hpp" -#include "x11/connection.hpp" #include "x11/tray_manager.hpp" using namespace polybar; diff --git a/src/utils/env.cpp b/src/utils/env.cpp index d4eb5b7d..575ffb42 100644 --- a/src/utils/env.cpp +++ b/src/utils/env.cpp @@ -8,13 +8,13 @@ POLYBAR_NS namespace env_util { - bool has(const char* var) { - const char* env{std::getenv(var)}; + bool has(const string& var) { + const char* env{std::getenv(var.c_str())}; return env != nullptr && std::strlen(env) > 0; } - string get(const char* var, string fallback) { - const char* value{std::getenv(var)}; + string get(const string& var, string fallback) { + const char* value{std::getenv(var.c_str())}; return value != nullptr ? value : move(fallback); } } diff --git a/src/utils/file.cpp b/src/utils/file.cpp index 90a2289a..c2d73881 100644 --- a/src/utils/file.cpp +++ b/src/utils/file.cpp @@ -7,6 +7,7 @@ #include #include "errors.hpp" +#include "utils/env.hpp" #include "utils/file.hpp" POLYBAR_NS @@ -207,11 +208,17 @@ namespace file_util { /** * Get glob results using given pattern */ - vector glob(const string& pattern) { + vector glob(string pattern) { glob_t result{}; vector ret; - if (glob(pattern.c_str(), GLOB_TILDE, nullptr, &result) == 0) { + // Manually expand tilde to fix builds using versions of libc + // that doesn't provide the GLOB_TILDE flag (musl for example) + if (pattern[0] == '~') { + pattern.replace(0, 1, env_util::get("HOME")); + } + + if (::glob(pattern.c_str(), 0, nullptr, &result) == 0) { for (size_t i = 0_z; i < result.gl_pathc; ++i) { ret.emplace_back(result.gl_pathv[i]); }