diff options
Diffstat (limited to 'src/run')
| -rw-r--r-- | src/run/var.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/run/var.rs b/src/run/var.rs index d3e98f4..8e22f5c 100644 --- a/src/run/var.rs +++ b/src/run/var.rs @@ -1,5 +1,6 @@ use std::borrow::Cow; use std::collections::{HashMap, HashSet}; +use std::os::unix::ffi::OsStrExt; use std::sync::LazyLock; use std::time::Instant; @@ -19,7 +20,10 @@ impl Vars { magic: HashMap<BString, fn() -> BString>, ) -> Self { for (var, val) in std::env::vars_os() { - simple.insert(var.into_encoded_bytes(), val.into_encoded_bytes()); + // explicitly added variables get priority. + if !simple.contains_key(var.as_bytes()) { + simple.insert(var.into_encoded_bytes(), val.into_encoded_bytes()); + } } let all = simple .keys() @@ -87,10 +91,15 @@ macro_rules! map { impl Default for Vars { fn default() -> Self { + use crate::basedir::xdg; + let simple = map! { b"PISH_VERSION" => crate::consts::PISH_VERSION.as_bytes().to_vec(), b"PISH_COMMIT" => crate::consts::PISH_COMMIT.as_bytes().to_vec(), b"PISH_DIRTY" => vec![crate::consts::PISH_DIRTY as u8 + b'0'], + xdg::DATA_HOME => xdg::data_home().as_os_str().as_bytes().to_vec(), + xdg::STATE_HOME => xdg::state_home().as_os_str().as_bytes().to_vec(), + xdg::CONFIG_HOME => xdg::config_home().as_os_str().as_bytes().to_vec(), }; let magic = map! { @@ -101,7 +110,13 @@ impl Default for Vars { // call it once such that lazylock gets initialized seconds_since_startup(); - Self::new(simple, magic) + let mut this = Self::new(simple.clone(), magic); + for var in simple.keys() { + if var.starts_with(b"XDG_") { + this.allow_export(var, true); + } + } + this } } |
