Create default config (#2511)

* Create default config and install to /etc/polybar

Closes #2405

* Search for config in /etc

We search in XDG_CONFIG_DIRS, /etc/xdg, and /etc but only for config.ini

Closes #2016

* Remove config installation from build.sh

* Remove userconfig cmake file

* Cleanup

* Cleanup default config

* Update CHANGELOG.md

Co-authored-by: dvermd <315743+dvermd@users.noreply.github.com>

* Update src/main.cpp

Co-authored-by: dvermd <315743+dvermd@users.noreply.github.com>

* Add tests for string functions

* Support loading bars from fallbacks in /etc

* Combine duplicate string_util::contains test

Co-authored-by: dvermd <315743+dvermd@users.noreply.github.com>
This commit is contained in:
Patrick Ziegler
2021-10-05 13:07:19 +02:00
committed by GitHub
parent 98dffc292a
commit 282b0f4e73
20 changed files with 316 additions and 649 deletions

View File

@ -269,30 +269,47 @@ namespace file_util {
* Search for polybar config and returns the path if found
*/
string get_config_path() {
string confpath;
if (env_util::has("XDG_CONFIG_HOME")) {
confpath = env_util::get("XDG_CONFIG_HOME") + "/polybar/config";
if (exists(confpath)) {
return confpath;
}
const static string suffix = "/polybar/config";
string iniConfPath = confpath.append(".ini");
if (exists(iniConfPath)) {
return iniConfPath;
}
vector<string> possible_paths;
if (env_util::has("XDG_CONFIG_HOME")) {
auto path = env_util::get("XDG_CONFIG_HOME") + suffix;
possible_paths.push_back(path);
possible_paths.push_back(path + ".ini");
}
if (env_util::has("HOME")) {
confpath = env_util::get("HOME") + "/.config/polybar/config";
if (exists(confpath)) {
return confpath;
}
auto path = env_util::get("HOME") + "/.config" + suffix;
string iniConfPath = confpath.append(".ini");
if (exists(iniConfPath)) {
return iniConfPath;
possible_paths.push_back(path);
possible_paths.push_back(path + ".ini");
}
vector<string> xdg_config_dirs;
/*
*Ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
*/
if (env_util::has("XDG_CONFIG_DIRS")) {
xdg_config_dirs = string_util::split(env_util::get("XDG_CONFIG_DIRS"), ':');
} else {
xdg_config_dirs.push_back("/etc/xdg");
}
for (const string& xdg_config_dir : xdg_config_dirs) {
possible_paths.push_back(xdg_config_dir + suffix + ".ini");
}
possible_paths.push_back("/etc" + suffix + ".ini");
for (const string& p : possible_paths) {
if (exists(p)) {
return p;
}
}
return "";
}