refactor(file_util): Expand tilde manually
This commit is contained in:
parent
9d589fa5a7
commit
95d5b03fa2
@ -5,8 +5,8 @@
|
|||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
namespace env_util {
|
namespace env_util {
|
||||||
bool has(const char* var);
|
bool has(const string& var);
|
||||||
string get(const char* var, string fallback = "");
|
string get(const string& var, string fallback = "");
|
||||||
}
|
}
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -105,7 +105,7 @@ namespace file_util {
|
|||||||
string pick(const vector<string>& filenames);
|
string pick(const vector<string>& filenames);
|
||||||
string contents(const string& filename);
|
string contents(const string& filename);
|
||||||
bool is_fifo(const string& filename);
|
bool is_fifo(const string& filename);
|
||||||
vector<string> glob(const string& pattern);
|
vector<string> glob(string pattern);
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
decltype(auto) make_file_descriptor(Args&&... args) {
|
decltype(auto) make_file_descriptor(Args&&... args) {
|
||||||
|
@ -149,7 +149,7 @@ target_compile_options(${PROJECT_NAME} PUBLIC
|
|||||||
# Create executable target: ipc messager {{{
|
# Create executable target: ipc messager {{{
|
||||||
|
|
||||||
if(BUILD_IPC_MSG)
|
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
|
target_compile_options(${PROJECT_NAME}-msg PUBLIC
|
||||||
$<$<CXX_COMPILER_ID:GNU>:$<$<CONFIG:MinSizeRel>:-flto>>)
|
$<$<CXX_COMPILER_ID:GNU>:$<$<CONFIG:MinSizeRel>:-flto>>)
|
||||||
endif()
|
endif()
|
||||||
|
@ -1,19 +1,13 @@
|
|||||||
#include "common.hpp"
|
|
||||||
#include "components/bar.hpp"
|
#include "components/bar.hpp"
|
||||||
#include "components/command_line.hpp"
|
#include "components/command_line.hpp"
|
||||||
#include "components/config.hpp"
|
#include "components/config.hpp"
|
||||||
#include "components/controller.hpp"
|
#include "components/controller.hpp"
|
||||||
#include "components/ipc.hpp"
|
#include "components/ipc.hpp"
|
||||||
#include "components/logger.hpp"
|
|
||||||
#include "components/parser.hpp"
|
#include "components/parser.hpp"
|
||||||
#include "components/renderer.hpp"
|
#include "components/renderer.hpp"
|
||||||
#include "settings.hpp"
|
|
||||||
#include "utils/env.hpp"
|
#include "utils/env.hpp"
|
||||||
#include "utils/file.hpp"
|
|
||||||
#include "utils/inotify.hpp"
|
#include "utils/inotify.hpp"
|
||||||
#include "utils/io.hpp"
|
|
||||||
#include "utils/process.hpp"
|
#include "utils/process.hpp"
|
||||||
#include "x11/connection.hpp"
|
|
||||||
#include "x11/tray_manager.hpp"
|
#include "x11/tray_manager.hpp"
|
||||||
|
|
||||||
using namespace polybar;
|
using namespace polybar;
|
||||||
|
@ -8,13 +8,13 @@
|
|||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
namespace env_util {
|
namespace env_util {
|
||||||
bool has(const char* var) {
|
bool has(const string& var) {
|
||||||
const char* env{std::getenv(var)};
|
const char* env{std::getenv(var.c_str())};
|
||||||
return env != nullptr && std::strlen(env) > 0;
|
return env != nullptr && std::strlen(env) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
string get(const char* var, string fallback) {
|
string get(const string& var, string fallback) {
|
||||||
const char* value{std::getenv(var)};
|
const char* value{std::getenv(var.c_str())};
|
||||||
return value != nullptr ? value : move(fallback);
|
return value != nullptr ? value : move(fallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <streambuf>
|
#include <streambuf>
|
||||||
|
|
||||||
#include "errors.hpp"
|
#include "errors.hpp"
|
||||||
|
#include "utils/env.hpp"
|
||||||
#include "utils/file.hpp"
|
#include "utils/file.hpp"
|
||||||
|
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
@ -207,11 +208,17 @@ namespace file_util {
|
|||||||
/**
|
/**
|
||||||
* Get glob results using given pattern
|
* Get glob results using given pattern
|
||||||
*/
|
*/
|
||||||
vector<string> glob(const string& pattern) {
|
vector<string> glob(string pattern) {
|
||||||
glob_t result{};
|
glob_t result{};
|
||||||
vector<string> ret;
|
vector<string> 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) {
|
for (size_t i = 0_z; i < result.gl_pathc; ++i) {
|
||||||
ret.emplace_back(result.gl_pathv[i]);
|
ret.emplace_back(result.gl_pathv[i]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user