mirror of
https://github.com/sharkdp/bat.git
synced 2025-07-01 06:40:42 +02:00
Updated bat config dir for MacOs
Removed directories crate and using dirs_rs Changed bat config file and cache dir on MacOs: config: ~/.config/bat/config cache: ~/.config/bat/cache/
This commit is contained in:
60
src/dirs.rs
60
src/dirs.rs
@ -1,6 +1,60 @@
|
||||
use directories::ProjectDirs;
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref PROJECT_DIRS: ProjectDirs =
|
||||
ProjectDirs::from("", "", crate_name!()).expect("Could not get home directory");
|
||||
pub static ref PROJECT_DIRS: BatProjectDirs =
|
||||
BatProjectDirs::new().expect("Could not get home directory");
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ extern crate ansi_term;
|
||||
extern crate atty;
|
||||
extern crate console;
|
||||
extern crate content_inspector;
|
||||
extern crate directories;
|
||||
extern crate dirs as dirs_rs;
|
||||
extern crate encoding;
|
||||
extern crate git2;
|
||||
extern crate shell_words;
|
||||
|
Reference in New Issue
Block a user