1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use {
directories,
std::path::{Path, PathBuf},
};
mod conf;
mod format;
mod verb_conf;
pub use {
conf::Conf,
format::*,
once_cell::sync::Lazy,
verb_conf::VerbConf,
};
pub const DEFAULT_CONF_FILE: &str = include_str!("../../resources/default-conf.hjson");
pub fn app_dirs() -> directories::ProjectDirs {
directories::ProjectDirs::from("org", "dystroy", "broot")
.expect("Unable to find configuration directories")
}
#[cfg(not(target_os = "macos"))]
fn find_conf_dir() -> PathBuf {
app_dirs().config_dir().to_path_buf()
}
#[cfg(target_os = "macos")]
fn find_conf_dir() -> PathBuf {
if let Some(user_dirs) = directories::UserDirs::new() {
let prefered = user_dirs.home_dir().join(".config/broot");
if prefered.exists() {
return prefered;
}
let second_choice = app_dirs().config_dir().to_path_buf();
if second_choice.exists() {
return second_choice;
}
return prefered;
} else {
app_dirs().config_dir().to_path_buf()
}
}
static CONF_DIR: Lazy<PathBuf> = Lazy::new(find_conf_dir);
pub fn dir() -> &'static Path {
&*CONF_DIR
}