bindings: Support a bindings file in $XDG_CONFIG_HOME/ncmpcpp
Fixes https://github.com/arybczak/ncmpcpp/issues/91 This also rewrites the intro in doc/bindings to be more like doc/config.
This commit is contained in:
committed by
Andrzej Rybczak
parent
67df6b556b
commit
e107edd4cd
@@ -1,7 +1,8 @@
|
|||||||
##########################################################
|
##############################################################
|
||||||
## this is example bindings configuration file, copy it ##
|
## This is the example bindings file. Copy it to ##
|
||||||
## to ~/.ncmpcpp/bindings and set up your preferences ##
|
## ~/.ncmpcpp/bindings or $XDG_CONFIG_HOME/ncmpcpp/bindings ##
|
||||||
##########################################################
|
## and set up your preferences ##
|
||||||
|
##############################################################
|
||||||
##
|
##
|
||||||
##### General rules #####
|
##### General rules #####
|
||||||
##
|
##
|
||||||
|
|||||||
@@ -467,6 +467,17 @@ bool BindingsConfiguration::read(const std::string &file)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BindingsConfiguration::read(const std::vector<std::string> &binding_paths)
|
||||||
|
{
|
||||||
|
return std::all_of(
|
||||||
|
binding_paths.begin(),
|
||||||
|
binding_paths.end(),
|
||||||
|
[&](const std::string &binding_path) {
|
||||||
|
return read(binding_path);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void BindingsConfiguration::generateDefaults()
|
void BindingsConfiguration::generateDefaults()
|
||||||
{
|
{
|
||||||
NC::Key::Type k = NC::Key::None;
|
NC::Key::Type k = NC::Key::None;
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public:
|
|||||||
typedef BindingsMap::value_type::second_type::const_iterator ConstBindingIterator;
|
typedef BindingsMap::value_type::second_type::const_iterator ConstBindingIterator;
|
||||||
typedef std::pair<BindingIterator, BindingIterator> BindingIteratorPair;
|
typedef std::pair<BindingIterator, BindingIterator> BindingIteratorPair;
|
||||||
|
|
||||||
bool read(const std::string &file);
|
bool read(const std::vector<std::string> &binding_paths);
|
||||||
void generateDefaults();
|
void generateDefaults();
|
||||||
|
|
||||||
const Command *findCommand(const std::string &name);
|
const Command *findCommand(const std::string &name);
|
||||||
@@ -111,6 +111,8 @@ private:
|
|||||||
m_bindings[k].push_back(std::forward<ArgT>(t));
|
m_bindings[k].push_back(std::forward<ArgT>(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool read(const std::string &file);
|
||||||
|
|
||||||
BindingsMap m_bindings;
|
BindingsMap m_bindings;
|
||||||
CommandsSet m_commands;
|
CommandsSet m_commands;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -74,7 +74,12 @@ bool configure(int argc, char **argv)
|
|||||||
xdg_config_home() + "ncmpcpp/config"
|
xdg_config_home() + "ncmpcpp/config"
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string bindings_path;
|
const std::vector<std::string> default_bindings_paths = {
|
||||||
|
"~/.ncmpcpp/bindings",
|
||||||
|
xdg_config_home() + "ncmpcpp/bindings"
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<std::string> bindings_paths;
|
||||||
std::vector<std::string> config_paths;
|
std::vector<std::string> config_paths;
|
||||||
|
|
||||||
po::options_description options("Options");
|
po::options_description options("Options");
|
||||||
@@ -85,7 +90,7 @@ bool configure(int argc, char **argv)
|
|||||||
("config,c", po::value<std::vector<std::string>>(&config_paths)->value_name("PATH")->default_value(default_config_paths, join<std::string>(default_config_paths, " AND ")), "specify configuration file(s)")
|
("config,c", po::value<std::vector<std::string>>(&config_paths)->value_name("PATH")->default_value(default_config_paths, join<std::string>(default_config_paths, " AND ")), "specify configuration file(s)")
|
||||||
("ignore-config-errors", "ignore unknown and invalid options in configuration files")
|
("ignore-config-errors", "ignore unknown and invalid options in configuration files")
|
||||||
("test-lyrics-fetchers", "check if lyrics fetchers work")
|
("test-lyrics-fetchers", "check if lyrics fetchers work")
|
||||||
("bindings,b", po::value<std::string>(&bindings_path)->value_name("PATH")->default_value("~/.ncmpcpp/bindings"), "specify bindings file")
|
("bindings,b", po::value<std::vector<std::string>>(&bindings_paths)->value_name("PATH")->default_value(default_bindings_paths, join<std::string>(default_bindings_paths, " AND ")), "specify bindings file(s)")
|
||||||
("screen,s", po::value<std::string>()->value_name("SCREEN"), "specify the startup screen")
|
("screen,s", po::value<std::string>()->value_name("SCREEN"), "specify the startup screen")
|
||||||
("slave-screen,S", po::value<std::string>()->value_name("SCREEN"), "specify the startup slave screen")
|
("slave-screen,S", po::value<std::string>()->value_name("SCREEN"), "specify the startup slave screen")
|
||||||
("help,?", "show help message")
|
("help,?", "show help message")
|
||||||
@@ -190,14 +195,9 @@ bool configure(int argc, char **argv)
|
|||||||
if (Config.read(config_paths, vm.count("ignore-config-errors")) == false)
|
if (Config.read(config_paths, vm.count("ignore-config-errors")) == false)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
// if bindings file was not specified, use the one from main directory.
|
|
||||||
if (vm["bindings"].defaulted())
|
|
||||||
bindings_path = Config.ncmpcpp_directory + "bindings";
|
|
||||||
else
|
|
||||||
expand_home(bindings_path);
|
|
||||||
|
|
||||||
// read bindings
|
// read bindings
|
||||||
if (Bindings.read(bindings_path) == false)
|
std::for_each(bindings_paths.begin(), bindings_paths.end(), expand_home);
|
||||||
|
if (Bindings.read(bindings_paths) == false)
|
||||||
exit(1);
|
exit(1);
|
||||||
Bindings.generateDefaults();
|
Bindings.generateDefaults();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user