packages: Fix performance bug

This commit is contained in:
Dylan Araps 2018-06-03 14:52:22 +10:00
parent 7696f58ea4
commit e3723d277c

100
neofetch
View file

@ -1235,82 +1235,88 @@ get_uptime() {
} }
get_packages() { get_packages() {
# pkgs: Run package manager if it exists. # has: Check if package manager installed.
# tots: Count lines in command output. # dir: Count files or dirs in a glob.
# dirc: Count files or dirs in a glob. # pac: If packages > 0, log package manager name.
pkgs() { type -p "$1" >/dev/null && { ((packages+="$2"));(("$2">0))&&managers+="$_, "; }; } # tot: Count lines in command output.
tots() { IFS=$'\n' read -d "" -ra files < <($1); echo "${#files[@]}"; } has() { type -p "$1" >/dev/null && manager="$_"; }
dirc() { echo $#; } dir() { ((packages+=$#)); pac "$#"; }
pac() { (($1 > 0)) && managers+="${manager}, "; }
tot() { IFS=$'\n' read -d "" -ra pkgs < <("$@");((packages+="${#pkgs[@]}"));pac "${#pkgs[@]}"; }
case "$os" in case "$os" in
"Linux" | "BSD" | "iPhone OS" | "Solaris") "Linux" | "BSD" | "iPhone OS" | "Solaris")
pkgs "pacman-key" "$(tots "pacman -Qq --color never")" # Package Manager Programs.
pkgs "rpm" "$(tots "rpm -qa")" has "pacman-key" && tot pacman -Qq --color never
pkgs "xbps-query" "$(tots "xbps-query -l")" has "dpkg" && tot dpkg-query -f '\n' -W
pkgs "apk" "$(tots "apk info")" has "rpm" && tot rpm -qa
pkgs "opkg" "$(tots "opkg list-installed")" has "xbps-query" && tot xbps-query -l
pkgs "pacman-g2" "$(tots "pacman-g2 -Q")" has "apk" && tot apk info
pkgs "lvu" "$(tots "lvu installed")" has "opkg" && tot opkg list-installed
pkgs "tce-status" "$(tots "tce-status -i")" has "pacman-g2" && tot pacman-g2 -Q
pkgs "pkg_info" "$(tots "pkg_info")" has "lvu" && tot lvu installed
pkgs "tazpkg" "$(tots "tazpkg list") - 6" has "tce-status" && tot tce-status -i
pkgs "sorcery" "$(tots "gaze installed")" has "pkg_info" && tot pkg_info
pkgs "alps" "$(tots "alps showinstalled")" has "tazpkg" && tot tazpkg list && ((packages-=6))
pkgs "butch" "$(tots "butch list")" has "sorcery" && tot gaze installed
pkgs "emerge" "$(dirc /var/db/pkg/*/*/)" has "alps" && tot alps showinstalled
pkgs "nix-env" "$(dirc /nix/store/*/)" has "butch" && tot butch list
pkgs "guix" "$(dirc /gnu/store/*/)"
pkgs "Compile" "$(dirc /Programs/*/)" # Counting files/dirs.
pkgs "eopkg" "$(dirc /var/lib/eopkg/package/*)" has "emerge" && dir /var/db/pkg/*/*/
pkgs "crew" "$(dirc /usr/local/etc/crew/meta/*.filelist)" has "nix-env" && dir /nix/store/*/
pkgs "pkgtool" "$(dirc /var/log/packages/*)" has "guix" && dir /gnu/store/*/
pkgs "cave" "$(dirc /var/db/paludis/repositories/cross-installed/*/data/*/ \ has "Compile" && dir /Programs/*/
/var/db/paludis/repositories/installed/data/*/)" has "eopkg" && dir /var/lib/eopkg/package/*
pkgs "kpm-pkg" "$(kpm --get-selections | grep -cv deinstall$)" has "crew" && dir /usr/local/etc/crew/meta/*.filelist
pkgs "dpkg" "$(dpkg --get-selections | grep -cv deinstall$)" has "pkgtool" && dir /var/log/packages/*
has "cave" && dir /var/db/paludis/repositories/cross-installed/*/data/*/ \
/var/db/paludis/repositories/installed/data/*/
# Other (Needs complex command)
has "kpm-pkg" && ((packages+="$(kpm --get-selections | grep -cv deinstall$)"))
case "$kernel_name" in case "$kernel_name" in
"FreeBSD") pkgs "pkg" "$(tots "pkg info")" ;; "FreeBSD") has "pkg" && tot pkg info ;;
"SunOS") pkgs "pkginfo" "$(tots "pkginfo -i")" ;; "SunOS") has "pkginfo" && tot pkginfo -i ;;
*) *)
pkgs "pkg" "$(dirc /var/db/pkg/*)" has "pkg" && dir /var/db/pkg/*
((packages == 0)) && \ ((packages == 0)) && \
pkgs "pkg" "$(tots "pkg list")" has "pkg" && tot pkg list
;; ;;
esac esac
;; ;;
"Mac OS X" | "MINIX") "Mac OS X" | "MINIX")
pkgs "port" "$(tots "port installed") - 1" has "port" && tot port installed && ((packages-=1))
pkgs "brew" "$(dirc /usr/local/Cellar/*) - 1" has "brew" && dir /usr/local/Cellar/*
pkgs "pkgin" "$(tots "pkgin list")" has "pkgin" && tot pkgin list
;; ;;
"AIX"| "FreeMiNT") "AIX"| "FreeMiNT")
pkgs "lslpp" "$(lslpp -J -l -q | grep -cv '^#')" has "lslpp" && ((packages+="$(lslpp -J -l -q | grep -cv '^#')"))
pkgs "rpm" "$(tots "rpm -qa")" has "rpm" && tot rpm -qa
;; ;;
"Windows") "Windows")
case "$kernel_name" in case "$kernel_name" in
"CYGWIN"*) pkgs "cygcheck" "$(tots "cygcheck -cd")" ;; "CYGWIN"*) has "cygcheck" && tot cygcheck -cd ;;
"MSYS"*) pkgs "pacman" "$(tots "pacman -Qq --color never")" ;; "MSYS"*) has "pacman" && tot pacman -Qq --color never ;;
esac esac
# Count chocolatey packages. # Count chocolatey packages.
[[ -d "/cygdrive/c/ProgramData/chocolatey/lib" ]] && \ [[ -d "/cygdrive/c/ProgramData/chocolatey/lib" ]] && \
pkgs ":" "$(dirc /cygdrive/c/ProgramData/chocolatey/lib/*)" dir /cygdrive/c/ProgramData/chocolatey/lib/*
;; ;;
"Haiku") "Haiku")
files=(/boot/system/package-links/*) dir /boot/system/package-links/*
packages="${#files[@]}"
;; ;;
"IRIX") "IRIX")
packages="$(($(tots "versions -b")-3))" tot versions -b
((packages-=3))
;; ;;
esac esac
@ -1319,7 +1325,7 @@ get_packages() {
elif [[ "$package_managers" == "on" && "${managers//,}" ]]; then elif [[ "$package_managers" == "on" && "${managers//,}" ]]; then
managers="${managers/pacman-key/pacman}" managers="${managers/pacman-key/pacman}"
managers="${managers/kpt-pkg/kpt}" managers="${managers/nix-env/nix}"
packages+=" (${managers%,*})" packages+=" (${managers%,*})"
fi fi
} }