2use std::path::{Path, PathBuf};
4#[cfg(target_os = "macos")]
7/// Wrapper for 'dirs' that treats MacOS more like Linux, by following the XDG specification.
8/// This means that the `XDG_CACHE_HOME` and `XDG_CONFIG_HOME` environment variables are
9/// checked first. The fallback directories are `~/.cache/bat` and `~/.config/bat`, respectively.
10pub struct BatProjectDirs {
16 fn new() -> Option<BatProjectDirs> {
17 #[cfg(target_os = "macos")]
18 let cache_dir_op = env::var_os("XDG_CACHE_HOME")
20 .filter(|p| p.is_absolute())
21 .or_else(|| dirs_rs::home_dir().map(|d| d.join(".cache")));
23 #[cfg(not(target_os = "macos"))]
24 let cache_dir_op = dirs_rs::cache_dir();
26 let cache_dir = cache_dir_op.map(|d| d.join("bat"))?;
28 #[cfg(target_os = "macos")]
29 let config_dir_op = env::var_os("XDG_CONFIG_HOME")
31 .filter(|p| p.is_absolute())
32 .or_else(|| dirs_rs::home_dir().map(|d| d.join(".config")));
34 #[cfg(not(target_os = "macos"))]
35 let config_dir_op = dirs_rs::config_dir();
37 let config_dir = config_dir_op.map(|d| d.join("bat"))?;
45 pub fn cache_dir(&self) -> &Path {
49 pub fn config_dir(&self) -> &Path {
55 pub static ref PROJECT_DIRS: BatProjectDirs =
56 BatProjectDirs::new().expect("Could not get home directory");
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list