mirror of
https://github.com/polybar/polybar.git
synced 2024-11-03 04:33:30 -05:00
fix(config): Expand all environment variables and file references (#724)
This commit is contained in:
parent
e381d76908
commit
e329a8150a
3 changed files with 19 additions and 5 deletions
|
@ -338,6 +338,7 @@ class config {
|
|||
fallback = var.substr(pos + 1);
|
||||
var.erase(pos);
|
||||
}
|
||||
var = file_util::expand(var);
|
||||
|
||||
if (file_util::exists(var)) {
|
||||
m_log.info("File reference \"%s\" found", var);
|
||||
|
|
|
@ -73,7 +73,8 @@ if(BUILD_IPC_MSG)
|
|||
SOURCES
|
||||
ipc.cpp
|
||||
utils/env.cpp
|
||||
utils/file.cpp)
|
||||
utils/file.cpp
|
||||
utils/string.cpp)
|
||||
target_compile_options(polybar-msg PUBLIC $<$<CXX_COMPILER_ID:GNU>:$<$<CONFIG:MinSizeRel>:-flto>>)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "errors.hpp"
|
||||
#include "utils/env.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -236,11 +237,22 @@ namespace file_util {
|
|||
* Path expansion
|
||||
*/
|
||||
const string expand(const string& path) {
|
||||
string p{path};
|
||||
if (p[0] == '~') {
|
||||
p.replace(0, 1, env_util::get("HOME"));
|
||||
string ret;
|
||||
vector<string> p_exploded = string_util::split(path, '/');
|
||||
for (auto& section : p_exploded) {
|
||||
switch(section[0]) {
|
||||
case '$':
|
||||
section = env_util::get(section.substr(1));
|
||||
break;
|
||||
case '~':
|
||||
section = env_util::get("HOME");
|
||||
break;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
ret = string_util::join(p_exploded, "/");
|
||||
if (ret[0] != '/')
|
||||
ret.insert(0, 1, '/');
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue