diff --git a/build.rs b/build.rs index c4c6af6c8..634011f42 100644 --- a/build.rs +++ b/build.rs @@ -5,8 +5,9 @@ use std::{env, fs}; fn main() { cfg_aliases::cfg_aliases! { - vfox: { any(feature = "vfox", target_os = "windows") }, asdf: { any(feature = "asdf", not(target_os = "windows")) }, + macos: { target_os = "macos" }, + vfox: { any(feature = "vfox", target_os = "windows") }, } built::write_built_file().expect("Failed to acquire build-time information"); diff --git a/src/env.rs b/src/env.rs index b108586c9..14c8e1d7c 100644 --- a/src/env.rs +++ b/src/env.rs @@ -33,16 +33,29 @@ pub static HOME: Lazy = pub static EDITOR: Lazy = Lazy::new(|| var("VISUAL").unwrap_or_else(|_| var("EDITOR").unwrap_or_else(|_| "nano".into()))); -#[cfg(target_os = "macos")] +#[cfg(macos)] pub static XDG_CACHE_HOME: Lazy = Lazy::new(|| var_path("XDG_CACHE_HOME").unwrap_or_else(|| HOME.join("Library/Caches"))); -#[cfg(not(target_os = "macos"))] +#[cfg(windows)] +pub static XDG_CACHE_HOME: Lazy = Lazy::new(|| { + var_path("XDG_CACHE_HOME") + .or_else(|| var_path("TEMP")) + .unwrap_or_else(|| temp_dir()) +}); +#[cfg(all(not(windows), not(macos)))] pub static XDG_CACHE_HOME: Lazy = Lazy::new(|| var_path("XDG_CACHE_HOME").unwrap_or_else(|| HOME.join(".cache"))); pub static XDG_CONFIG_HOME: Lazy = Lazy::new(|| var_path("XDG_CONFIG_HOME").unwrap_or_else(|| HOME.join(".config"))); +#[cfg(unix)] pub static XDG_DATA_HOME: Lazy = Lazy::new(|| var_path("XDG_DATA_HOME").unwrap_or_else(|| HOME.join(".local").join("share"))); +#[cfg(windows)] +pub static XDG_DATA_HOME: Lazy = Lazy::new(|| { + var_path("XDG_DATA_HOME") + .or(var_path("LOCALAPPDATA")) + .unwrap_or_else(|| HOME.join("AppData/Local")) +}); pub static XDG_STATE_HOME: Lazy = Lazy::new(|| var_path("XDG_STATE_HOME").unwrap_or_else(|| HOME.join(".local").join("state")));