Skip to main content

yui/
vars.rs

1//! Built-in `yui.*` variables exposed to Tera contexts.
2
3use camino::Utf8Path;
4use serde::Serialize;
5
6#[derive(Debug, Clone, Serialize)]
7pub struct YuiVars {
8    /// `"windows"` / `"macos"` / `"linux"` (from `std::env::consts::OS`).
9    pub os: String,
10    /// `"x86_64"` / `"aarch64"` (from `std::env::consts::ARCH`).
11    pub arch: String,
12    /// Machine hostname.
13    pub host: String,
14    /// Current user name.
15    pub user: String,
16    /// Absolute path to the dotfiles source repo (`$DOTFILES`).
17    pub source: String,
18}
19
20impl YuiVars {
21    pub fn detect(source: &Utf8Path) -> Self {
22        Self {
23            os: std::env::consts::OS.to_string(),
24            arch: std::env::consts::ARCH.to_string(),
25            host: whoami::hostname().unwrap_or_else(|_| "unknown".to_string()),
26            user: whoami::username().unwrap_or_else(|_| "unknown".to_string()),
27            source: source.to_string(),
28        }
29    }
30}