From a5e784c52804b0b2889d847469177ae3e57f2c34 Mon Sep 17 00:00:00 2001 From: Azalea Gui <22280294+hykilpikonna@users.noreply.github.com> Date: Thu, 21 Aug 2025 11:21:48 -0400 Subject: [PATCH] [F] Fix distro name detection --- Cargo.lock | 2 +- crates/hyfetch/src/bin/hyfetch.rs | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf43e996..4ddd33fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -251,7 +251,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hyfetch" -version = "2.0.0-rc5" +version = "2.0.0-rc6" dependencies = [ "aho-corasick", "ansi_colours", diff --git a/crates/hyfetch/src/bin/hyfetch.rs b/crates/hyfetch/src/bin/hyfetch.rs index 663c65e9..3c0b70d2 100644 --- a/crates/hyfetch/src/bin/hyfetch.rs +++ b/crates/hyfetch/src/bin/hyfetch.rs @@ -248,9 +248,7 @@ fn create_config( debug!(?det_ansi, "detected color mode"); // Try to get ascii from given backend first, if it fails, try neofetch backend - let asc = get_distro_ascii(distro, backend).or_else(|_| { - get_distro_ascii(distro, Backend::Neofetch).context("failed to get distro ascii from neofetch backend") - })?; + let asc = get_distro_ascii(distro, backend).or_else(|_| get_distro_ascii(distro, Backend::Neofetch)).context("failed to get distro ascii from neofetch backend")?; let asc = asc.to_normalized().context("failed to normalize ascii")?; let theme = det_bg.map(|bg| bg.theme()).unwrap_or_default(); let color_mode = det_ansi.unwrap_or(AnsiMode::Ansi256); @@ -769,13 +767,11 @@ fn create_config( }; // get distro string and convert it into the enum, neofetch friendly format, so we can check for small logos with the {distro}_small neofetch naming scheme. - let get_current_dst_str= get_distro_name(backend).context("failed to get current distro.")?; - - let detected_dst: Option = if distro.is_none() { - Some(format!("{:?}", Distro::detect(get_current_dst_str).unwrap())) - } else { - Some(distro.unwrap().to_string()) - }; + let tmp_dst = get_distro_name(backend).or_else(|_| get_distro_name(Backend::Neofetch)).context("failed to get distro name")?; + let detected_dst = Some(distro.map_or_else( + || format!("{:?}", Distro::detect(tmp_dst).unwrap()), + |d| d.to_string(), + )); // in case someone specified {distro}_small already in the --distro arg let detected_dst_small_fmt = if !detected_dst.clone().unwrap().ends_with("_small") {