fix!: fix OS and host detection on macOS
This commit is contained in:
parent
c7874fadf9
commit
40ed953f97
140
src/lib.rs
140
src/lib.rs
@ -100,11 +100,7 @@ pub fn total_packages(package_readout: &PackageReadout, skip_slow: bool) -> usiz
|
|||||||
.map(|mngr| packages(mngr, &macchina_package_count, skip_slow))
|
.map(|mngr| packages(mngr, &macchina_package_count, skip_slow))
|
||||||
.sum()
|
.sum()
|
||||||
}
|
}
|
||||||
"macos" => package_readout
|
"macos" => package_readout.count_pkgs().iter().map(|elem| elem.1).sum(),
|
||||||
.count_pkgs()
|
|
||||||
.iter()
|
|
||||||
.map(|elem| elem.1)
|
|
||||||
.sum(),
|
|
||||||
"freebsd" | "dragonfly" => run_and_count_lines("pkg", &["info"]),
|
"freebsd" | "dragonfly" => run_and_count_lines("pkg", &["info"]),
|
||||||
"openbsd" => match glob("/var/db/pkg/*/") {
|
"openbsd" => match glob("/var/db/pkg/*/") {
|
||||||
Ok(files) => files.count(),
|
Ok(files) => files.count(),
|
||||||
@ -130,7 +126,11 @@ fn get_macchina_package_count(
|
|||||||
|
|
||||||
/// return the amount of packages installed with a given linux package manager
|
/// return the amount of packages installed with a given linux package manager
|
||||||
/// Return `0` if the package manager is not installed
|
/// Return `0` if the package manager is not installed
|
||||||
fn packages(pkg_manager: &PackageManager, macchina_package_count: &[(String, usize)], skip_slow: bool) -> usize {
|
fn packages(
|
||||||
|
pkg_manager: &PackageManager,
|
||||||
|
macchina_package_count: &[(String, usize)],
|
||||||
|
skip_slow: bool,
|
||||||
|
) -> usize {
|
||||||
match pkg_manager {
|
match pkg_manager {
|
||||||
// libmacchina has very fast implementations for most package managers, so we use them
|
// libmacchina has very fast implementations for most package managers, so we use them
|
||||||
// where we can, otherwise we fall back to method used by dylans version of pfetch
|
// where we can, otherwise we fall back to method used by dylans version of pfetch
|
||||||
@ -234,9 +234,15 @@ pub fn memory(memory_readout: &MemoryReadout) -> Option<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn os(general_readout: &GeneralReadout) -> Option<String> {
|
pub fn os(general_readout: &GeneralReadout) -> Option<String> {
|
||||||
match general_readout.distribution() {
|
match env::consts::OS {
|
||||||
Ok(distribution) => Some(distribution),
|
"linux" => match general_readout.distribution() {
|
||||||
Err(_) => None,
|
Ok(distribution) => Some(distribution),
|
||||||
|
Err(_) => None,
|
||||||
|
},
|
||||||
|
_ => match general_readout.os_name() {
|
||||||
|
Ok(os) => Some(os),
|
||||||
|
Err(_) => None,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,61 +282,73 @@ pub fn uptime(general_readout: &GeneralReadout) -> Option<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn host() -> Option<String> {
|
pub fn host(general_readout: &GeneralReadout) -> Option<String> {
|
||||||
const BLACKLIST: &[&str] = &[
|
match env::consts::OS {
|
||||||
"To",
|
"linux" => {
|
||||||
"Be",
|
const BLACKLIST: &[&str] = &[
|
||||||
"be",
|
"To",
|
||||||
"Filled",
|
"Be",
|
||||||
"filled",
|
"be",
|
||||||
"By",
|
"Filled",
|
||||||
"by",
|
"filled",
|
||||||
"O.E.M.",
|
"By",
|
||||||
"OEM",
|
"by",
|
||||||
"Not",
|
"O.E.M.",
|
||||||
"Applicable",
|
"OEM",
|
||||||
"Specified",
|
"Not",
|
||||||
"System",
|
"Applicable",
|
||||||
"Product",
|
"Specified",
|
||||||
"Name",
|
"System",
|
||||||
"Version",
|
"Product",
|
||||||
"Undefined",
|
"Name",
|
||||||
"Default",
|
"Version",
|
||||||
"string",
|
"Undefined",
|
||||||
"INVALID",
|
"Default",
|
||||||
"<EFBFBD>",
|
"string",
|
||||||
"os",
|
"INVALID",
|
||||||
"Type1ProductConfigId",
|
"<EFBFBD>",
|
||||||
"",
|
"os",
|
||||||
];
|
"Type1ProductConfigId",
|
||||||
|
"",
|
||||||
|
];
|
||||||
|
|
||||||
// get device from system files
|
// get device from system files
|
||||||
let product_name =
|
let product_name =
|
||||||
fs::read_to_string("/sys/devices/virtual/dmi/id/product_name").unwrap_or_default();
|
fs::read_to_string("/sys/devices/virtual/dmi/id/product_name").unwrap_or_default();
|
||||||
let product_name = product_name.trim();
|
let product_name = product_name.trim();
|
||||||
let product_version =
|
let product_version = fs::read_to_string("/sys/devices/virtual/dmi/id/product_version")
|
||||||
fs::read_to_string("/sys/devices/virtual/dmi/id/product_version").unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let product_version = product_version.trim();
|
let product_version = product_version.trim();
|
||||||
let product_model =
|
let product_model =
|
||||||
fs::read_to_string("/sys/firmware/devicetree/base/model").unwrap_or_default();
|
fs::read_to_string("/sys/firmware/devicetree/base/model").unwrap_or_default();
|
||||||
let product_model = product_model.trim();
|
let product_model = product_model.trim();
|
||||||
|
|
||||||
let final_str = format!("{product_name} {product_version} {product_model}")
|
let final_str = format!("{product_name} {product_version} {product_model}")
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.filter(|word| !BLACKLIST.contains(word))
|
.filter(|word| !BLACKLIST.contains(word))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(" ");
|
.join(" ");
|
||||||
|
|
||||||
// if string is empty, display system architecture instead
|
// if string is empty, display system architecture instead
|
||||||
let final_str = if final_str.is_empty() {
|
let final_str = if final_str.is_empty() {
|
||||||
run_system_command("uname", &["-m"]).unwrap_or("Unknown".to_owned())
|
run_system_command("uname", &["-m"]).unwrap_or("Unknown".to_owned())
|
||||||
} else {
|
} else {
|
||||||
final_str
|
final_str
|
||||||
};
|
};
|
||||||
if final_str.is_empty() {
|
if final_str.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(final_str)
|
Some(final_str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"macos" => match general_readout.machine() {
|
||||||
|
Ok(host) => Some(host),
|
||||||
|
Err(_) => None,
|
||||||
|
},
|
||||||
|
_ => match general_readout.cpu_model_name() {
|
||||||
|
Ok(host) => Some(host),
|
||||||
|
Err(_) => None,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
src/main.rs
13
src/main.rs
@ -152,7 +152,11 @@ struct Readouts {
|
|||||||
kernel_readout: KernelReadout,
|
kernel_readout: KernelReadout,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_info(info: &PfetchInfo, readouts: &Readouts, skip_slow_package_managers: bool) -> Option<String> {
|
fn get_info(
|
||||||
|
info: &PfetchInfo,
|
||||||
|
readouts: &Readouts,
|
||||||
|
skip_slow_package_managers: bool,
|
||||||
|
) -> Option<String> {
|
||||||
match info {
|
match info {
|
||||||
PfetchInfo::Ascii => None,
|
PfetchInfo::Ascii => None,
|
||||||
PfetchInfo::Title => {
|
PfetchInfo::Title => {
|
||||||
@ -171,10 +175,13 @@ fn get_info(info: &PfetchInfo, readouts: &Readouts, skip_slow_package_managers:
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
PfetchInfo::Os => pfetch::os(&readouts.general_readout),
|
PfetchInfo::Os => pfetch::os(&readouts.general_readout),
|
||||||
PfetchInfo::Host => pfetch::host(),
|
PfetchInfo::Host => pfetch::host(&readouts.general_readout),
|
||||||
PfetchInfo::Kernel => pfetch::kernel(&readouts.kernel_readout),
|
PfetchInfo::Kernel => pfetch::kernel(&readouts.kernel_readout),
|
||||||
PfetchInfo::Uptime => pfetch::uptime(&readouts.general_readout),
|
PfetchInfo::Uptime => pfetch::uptime(&readouts.general_readout),
|
||||||
PfetchInfo::Pkgs => Some(pfetch::total_packages(&readouts.package_readout, skip_slow_package_managers).to_string()),
|
PfetchInfo::Pkgs => Some(
|
||||||
|
pfetch::total_packages(&readouts.package_readout, skip_slow_package_managers)
|
||||||
|
.to_string(),
|
||||||
|
),
|
||||||
PfetchInfo::Memory => pfetch::memory(&readouts.memory_readout),
|
PfetchInfo::Memory => pfetch::memory(&readouts.memory_readout),
|
||||||
PfetchInfo::Shell => match dotenvy::var("SHELL") {
|
PfetchInfo::Shell => match dotenvy::var("SHELL") {
|
||||||
Ok(shell) => Some(shell),
|
Ok(shell) => Some(shell),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user