~kennylevinsen/greetd-devel

Use a sysfs fallback if XDG_VTNR is undefined v1 PROPOSED

Hugo Osvaldo Barrera: 1
 Use a sysfs fallback if XDG_VTNR is undefined

 1 files changed, 15 insertions(+), 5 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~kennylevinsen/greetd-devel/patches/50045/mbox | git am -3
Learn more about email & git

[PATCH] Use a sysfs fallback if XDG_VTNR is undefined Export this patch

---
 agreety/src/main.rs | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/agreety/src/main.rs b/agreety/src/main.rs
index 67a87bf..1721c49 100644
--- a/agreety/src/main.rs
+++ b/agreety/src/main.rs
@@ -32,18 +32,28 @@ fn get_distro_name() -> Result<String, Box<dyn std::error::Error>> {
    maybe_unquote(general.get("PRETTY_NAME").ok_or("no pretty name")?)
}

/// Returns the current VT. May contain trailing whitespace.
fn get_vt() -> String {
    if let Ok(vtnr) = env::var("XDG_VTNR") {
        format!("tty{vtnr}")
    } else {
        if let Ok(tty) = std::fs::read_to_string("/sys/class/tty/tty0/active") {
            tty
        } else {
            String::from("tty0")
        }
    }
}

fn get_issue() -> Result<String, Box<dyn std::error::Error>> {
    let vtnr: usize = env::var("XDG_VTNR")
        .unwrap_or_else(|_| "0".to_string())
        .parse()
        .expect("unable to parse VTNR");
    let vt = get_vt();
    let uts = uname()?;
    Ok(fs::read_to_string("/etc/issue")?
        .replace(
            "\\S",
            &get_distro_name().unwrap_or_else(|_| "Linux".to_string()),
        )
        .replace("\\l", &format!("tty{vtnr}"))
        .replace("\\l", vt.trim())
        .replace("\\s", uts.sysname().to_str().unwrap())
        .replace("\\r", uts.release().to_str().unwrap())
        .replace("\\v", uts.version().to_str().unwrap())
-- 
2.44.0