feat: Support reading config from non-regular files (#2545)
We had a check that restricted config files to "regular files". This check was to restrictive as it didn't allow for things like: ``` polybar -c <(gen_config) gen_config | polybar -c /dev/stdin ``` Now, polybar can easily read config data from stdin.
This commit is contained in:
parent
6d1ff41d37
commit
9e3b537817
@ -73,6 +73,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- `DEBUG_SHADED` cmake variable and its associated functionality.
|
- `DEBUG_SHADED` cmake variable and its associated functionality.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
- Polybar can now read config files from stdin: `polybar -c /dev/stdin`.
|
||||||
- `custom/script`: Implement `env-*` config option.
|
- `custom/script`: Implement `env-*` config option.
|
||||||
([2090](https://github.com/polybar/polybar/issues/2090))
|
([2090](https://github.com/polybar/polybar/issues/2090))
|
||||||
- `drawtypes/ramp`: Add support for ramp weights.
|
- `drawtypes/ramp`: Add support for ramp weights.
|
||||||
|
@ -83,6 +83,7 @@ class fd_stream : public StreamType {
|
|||||||
namespace file_util {
|
namespace file_util {
|
||||||
bool exists(const string& filename);
|
bool exists(const string& filename);
|
||||||
bool is_file(const string& filename);
|
bool is_file(const string& filename);
|
||||||
|
bool is_dir(const string& filename);
|
||||||
string pick(const vector<string>& filenames);
|
string pick(const vector<string>& filenames);
|
||||||
string contents(const string& filename);
|
string contents(const string& filename);
|
||||||
void write_contents(const string& filename, const string& contents);
|
void write_contents(const string& filename, const string& contents);
|
||||||
|
@ -126,8 +126,8 @@ void config_parser::parse_file(const string& file, file_list path) {
|
|||||||
throw application_error("Failed to open config file " + file + ": " + strerror(errno));
|
throw application_error("Failed to open config file " + file + ": " + strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_util::is_file(file)) {
|
if (file_util::is_dir(file)) {
|
||||||
throw application_error("Config file " + file + " is not a file");
|
throw application_error("Config file " + file + " is a directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_log.trace("config_parser: Parsing %s", file);
|
m_log.trace("config_parser: Parsing %s", file);
|
||||||
|
@ -165,6 +165,19 @@ namespace file_util {
|
|||||||
return S_ISREG(buffer.st_mode);
|
return S_ISREG(buffer.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given path exists and is a file
|
||||||
|
*/
|
||||||
|
bool is_dir(const string& filename) {
|
||||||
|
struct stat buffer {};
|
||||||
|
|
||||||
|
if (stat(filename.c_str(), &buffer) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return S_ISDIR(buffer.st_mode);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Picks the first existing file out of given entries
|
* Picks the first existing file out of given entries
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user