2019-01-31 12:53:10 -05:00
|
|
|
use dirs_rs;
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
|
|
|
/// Wrapper for dirs that uses `~/.config/bat` for MacOS.
|
|
|
|
pub struct BatProjectDirs {
|
|
|
|
cache_dir: PathBuf,
|
|
|
|
config_dir: PathBuf,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BatProjectDirs {
|
|
|
|
fn new() -> Option<BatProjectDirs> {
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
let cache_dir = match dirs_rs::home_dir() {
|
|
|
|
Some(mut d) => {
|
|
|
|
d.push(".config/bat/cache");
|
|
|
|
d
|
|
|
|
}
|
|
|
|
None => return None,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
|
|
let cache_dir = match dirs_rs::cache_dir() {
|
|
|
|
Some(d) => d,
|
|
|
|
None => return None,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
let config_dir = match dirs_rs::home_dir() {
|
|
|
|
Some(mut d) => {
|
|
|
|
d.push(".config/bat");
|
|
|
|
d
|
|
|
|
}
|
|
|
|
None => return None,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
|
|
let config_dir = match dirs_rs::config_dir() {
|
|
|
|
Some(d) => d,
|
|
|
|
None => return None,
|
|
|
|
};
|
|
|
|
|
|
|
|
Some(BatProjectDirs {
|
|
|
|
cache_dir,
|
|
|
|
config_dir,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn cache_dir(&self) -> &Path {
|
|
|
|
&self.cache_dir
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn config_dir(&self) -> &Path {
|
|
|
|
&self.config_dir
|
|
|
|
}
|
|
|
|
}
|
2018-10-07 23:22:42 +02:00
|
|
|
|
|
|
|
lazy_static! {
|
2019-01-31 12:53:10 -05:00
|
|
|
pub static ref PROJECT_DIRS: BatProjectDirs =
|
|
|
|
BatProjectDirs::new().expect("Could not get home directory");
|
2018-10-07 23:22:42 +02:00
|
|
|
}
|