zerostack 1.3.3

Minimalistic coding agent written in Rust, optimized for memory footprint and performance
pub fn expand_tilde(s: &str) -> String {
    let home = || dirs::home_dir().map(|p| p.to_string_lossy().to_string());

    if s == "~" || s == "$HOME" {
        if let Some(h) = home() {
            return h;
        }
        return s.to_string();
    }
    if let Some(rest) = s.strip_prefix("~/") {
        if let Some(h) = home() {
            return std::path::Path::new(&h)
                .join(rest)
                .to_string_lossy()
                .to_string();
        }
        return s.to_string();
    }
    if let Some(rest) = s.strip_prefix("$HOME/") {
        if let Some(h) = home() {
            return std::path::Path::new(&h)
                .join(rest)
                .to_string_lossy()
                .to_string();
        }
    }
    s.to_string()
}