BREAKING CHANGE: function `total_packages` now requires the argument `skip_slow: bool` Add option to skip nix packages being counted. This can be enabled with `PF_FAST_PKG_COUNT`
This commit is contained in:
commit
c3ea78cb98
@ -73,7 +73,7 @@ pub enum PackageManager {
|
||||
|
||||
/// Obtain the amount of installed packages on the system by checking all installed supported package
|
||||
/// managers and adding the amounts
|
||||
pub fn total_packages(package_readout: &PackageReadout) -> usize {
|
||||
pub fn total_packages(package_readout: &PackageReadout, skip_slow: bool) -> usize {
|
||||
match env::consts::OS {
|
||||
"linux" => {
|
||||
let macchina_package_count: Vec<(String, usize)> = package_readout
|
||||
@ -97,7 +97,7 @@ pub fn total_packages(package_readout: &PackageReadout) -> usize {
|
||||
PackageManager::Nix,
|
||||
]
|
||||
.iter()
|
||||
.map(|mngr| packages(mngr, &macchina_package_count))
|
||||
.map(|mngr| packages(mngr, &macchina_package_count, skip_slow))
|
||||
.sum()
|
||||
}
|
||||
"macos" => package_readout
|
||||
@ -130,7 +130,7 @@ fn get_macchina_package_count(
|
||||
|
||||
/// return the amount of packages installed with a given linux package manager
|
||||
/// Return `0` if the package manager is not installed
|
||||
fn packages(pkg_manager: &PackageManager, macchina_package_count: &[(String, usize)]) -> usize {
|
||||
fn packages(pkg_manager: &PackageManager, macchina_package_count: &[(String, usize)], skip_slow: bool) -> usize {
|
||||
match pkg_manager {
|
||||
// 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
|
||||
@ -176,7 +176,7 @@ fn packages(pkg_manager: &PackageManager, macchina_package_count: &[(String, usi
|
||||
}
|
||||
// TODO: nix -q is very slow
|
||||
PackageManager::Nix => {
|
||||
if check_if_command_exists("nix-store") {
|
||||
if check_if_command_exists("nix-store") && !skip_slow {
|
||||
run_and_count_lines(
|
||||
"nix-store",
|
||||
&["-q", "--requisites", "/run/current-system/sw"],
|
||||
|
||||
10
src/main.rs
10
src/main.rs
@ -152,7 +152,7 @@ struct Readouts {
|
||||
kernel_readout: KernelReadout,
|
||||
}
|
||||
|
||||
fn get_info(info: &PfetchInfo, readouts: &Readouts) -> Option<String> {
|
||||
fn get_info(info: &PfetchInfo, readouts: &Readouts, skip_slow_package_managers: bool) -> Option<String> {
|
||||
match info {
|
||||
PfetchInfo::Ascii => None,
|
||||
PfetchInfo::Title => {
|
||||
@ -174,7 +174,7 @@ fn get_info(info: &PfetchInfo, readouts: &Readouts) -> Option<String> {
|
||||
PfetchInfo::Host => pfetch::host(),
|
||||
PfetchInfo::Kernel => pfetch::kernel(&readouts.kernel_readout),
|
||||
PfetchInfo::Uptime => pfetch::uptime(&readouts.general_readout),
|
||||
PfetchInfo::Pkgs => Some(pfetch::total_packages(&readouts.package_readout).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::Shell => match dotenvy::var("SHELL") {
|
||||
Ok(shell) => Some(shell),
|
||||
@ -199,6 +199,8 @@ fn main() {
|
||||
if let Ok(filepath) = dotenvy::var("PF_SOURCE") {
|
||||
dotenvy::from_path(filepath).unwrap();
|
||||
}
|
||||
// Check if SKIP_SLOW is enabled
|
||||
let skip_slow_package_managers = dotenvy::var("PF_FAST_PKG_COUNT").is_ok();
|
||||
|
||||
let enabled_pf_info_base: Vec<PfetchInfo> = match dotenvy::var("PF_INFO") {
|
||||
Ok(pfetch_infos) => pfetch_infos
|
||||
@ -242,7 +244,7 @@ fn main() {
|
||||
kernel_readout: KernelReadout::new(),
|
||||
};
|
||||
|
||||
let os = get_info(&PfetchInfo::Os, &readouts).unwrap_or_default();
|
||||
let os = get_info(&PfetchInfo::Os, &readouts, skip_slow_package_managers).unwrap_or_default();
|
||||
|
||||
let logo_override = env::var("PF_ASCII");
|
||||
|
||||
@ -269,7 +271,7 @@ fn main() {
|
||||
let gathered_pfetch_info: Vec<(pfetch::Color, String, String)> = enabled_pf_info
|
||||
.iter()
|
||||
.filter_map(|info| {
|
||||
let info_result = get_info(info, &readouts);
|
||||
let info_result = get_info(info, &readouts, skip_slow_package_managers);
|
||||
match info_result {
|
||||
Some(info_str) => match info {
|
||||
PfetchInfo::Title => Some((logo.secondary_color, info_str, "".to_string())),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user