mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-12 06:20:09 +01:00
fix: multiple xdg_config_dirs
This commit is contained in:
parent
7616ca183f
commit
45de0ad8e3
1 changed files with 15 additions and 10 deletions
|
|
@ -21,26 +21,31 @@ pub fn runtime_match(
|
|||
let xdg_config_home = std::env::var("XDG_CONFIG_HOME")
|
||||
.unwrap_or_else(|_| std::env::var("HOME").unwrap() + "/.config");
|
||||
let xdg_config_dirs = std::env::var("XDG_CONFIG_DIRS").unwrap_or("/etc/xdg".to_owned());
|
||||
let xdg_config_dirs = xdg_config_dirs.split(':').collect::<Vec<&str>>();
|
||||
|
||||
let user_rule_dir = format!("{}/pay-respects/rules", xdg_config_home);
|
||||
let system_rule_dir = format!("{}/pay-respects/rules", xdg_config_dirs);
|
||||
|
||||
|
||||
let user_rule_file = format!("{}/{}.toml", user_rule_dir, executable);
|
||||
let system_rule_file = format!("{}/{}.toml", system_rule_dir, executable);
|
||||
|
||||
let file;
|
||||
let mut file = Option::None;
|
||||
|
||||
if std::path::Path::new(&user_rule_file).exists() {
|
||||
file = user_rule_file;
|
||||
} else if std::path::Path::new(&system_rule_file).exists() {
|
||||
file = system_rule_file;
|
||||
file = Some(user_rule_file);
|
||||
} else {
|
||||
for dir in xdg_config_dirs {
|
||||
let rule_dir = format!("{}/pay-respects/rules", dir);
|
||||
let rule_file = format!("{}/{}.toml", rule_dir, executable);
|
||||
if std::path::Path::new(&rule_file).exists() {
|
||||
file = Some(rule_file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if file.is_none() {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
let file = std::fs::read_to_string(file).unwrap();
|
||||
let file = std::fs::read_to_string(file.unwrap()).unwrap();
|
||||
let rule: Rule = toml::from_str(&file).unwrap();
|
||||
let split_command = split_command(&last_command);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue