1pub mod info;
2use std::path::PathBuf;
3
4pub fn base_directories() -> Vec<PathBuf> {
7 let mut dirs: Vec<PathBuf> = Vec::new();
8
9 if let Ok(var_str) = std::env::var("XDG_DATA_DIRS") {
10 for p in var_str.split(":") {
11 let pb = PathBuf::from(p);
12
13 if pb.exists() {
14 dirs.push(pb);
15 }
16 }
17 }
18
19 if let Ok(var_str) = std::env::var("XDG_DATA_HOME") {
20 let pb = PathBuf::from(var_str);
21
22 if pb.exists() {
23 dirs.push(pb);
24 }
25 }
26
27 dirs
28}
29
30pub fn xdg_config_home() -> PathBuf {
31 let Ok(dir) = std::env::var("XDG_CONFIG_HOME") else {
32 let home = std::env::var("HOME").expect("CRITICAL: $HOME variable not set or available");
33 return PathBuf::from(home).join(".config");
34 };
35
36 PathBuf::from(dir)
37}
38
39pub fn xdg_data_home() -> PathBuf {
40 std::env::var_os("XDG_DATA_HOME")
41 .map(PathBuf::from)
42 .unwrap_or_else(|| {
43 let home = std::env::var_os("HOME")
44 .expect("$HOME environment variable not set. This is a critical failure");
45 PathBuf::from(home).join(".local/share")
46 })
47}
48
49pub fn xdg_data_dirs() -> Vec<PathBuf> {
50 let raw = std::env::var("XDG_DATA_DIRS")
51 .unwrap_or_else(|_| "/usr/local/share:/usr/share".to_string());
52 raw.split(':').map(PathBuf::from).collect()
53}