Wrong number of packages reported for some package managers (#1556)

* Wrong number of snap packages reported: fixed for snap (#1274)

* Adjusted indentation and improved packages count (#1274)

* Fixed spacing in empty lines
This commit is contained in:
Andrea Canepa 2020-10-04 13:53:30 +02:00 committed by GitHub
parent c155bdecd1
commit f730fc6a81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1478,21 +1478,28 @@ get_uptime() {
}
get_packages() {
# to adjust the number of pkgs per pkg manager
pkgs_h=0
# has: Check if package manager installed.
# dir: Count files or dirs in a glob.
# pac: If packages > 0, log package manager name.
# tot: Count lines in command output.
has() { type -p "$1" >/dev/null && manager=$1; }
dir() { ((packages+=$#)); pac "$#"; }
dir() { ((packages+=$#)); pac "$(($#-pkgs_h))"; }
pac() { (($1 > 0)) && { managers+=("$1 (${manager})"); manager_string+="${manager}, "; }; }
tot() { IFS=$'\n' read -d "" -ra pkgs <<< "$("$@")";((packages+=${#pkgs[@]}));pac "${#pkgs[@]}";}
tot() {
IFS=$'\n' read -d "" -ra pkgs <<< "$("$@")";
((packages+=${#pkgs[@]}));
pac "$((${#pkgs[@]}-pkgs_h))";
}
# Redefine tot() for Bedrock Linux.
[[ -f /bedrock/etc/bedrock-release && $PATH == */bedrock/cross/* ]] && {
tot() {
IFS=$'\n' read -d "" -ra pkgs <<< "$(for s in $(brl list); do strat -r "$s" "$@"; done)"
((packages+="${#pkgs[@]}"))
pac "${#pkgs[@]}"
pac "$((${#pkgs[@]}-pkgs_h))";
}
br_prefix="/bedrock/strata/*"
}
@ -1512,7 +1519,7 @@ get_packages() {
has lvu && tot lvu installed
has tce-status && tot tce-status -i
has pkg_info && tot pkg_info
has tazpkg && tot tazpkg list && ((packages-=6))
has tazpkg && pkgs_h=6 tot tazpkg list && ((packages-=6))
has sorcery && tot gaze installed
has alps && tot alps showinstalled
has butch && tot butch list
@ -1573,7 +1580,8 @@ get_packages() {
# Snap hangs if the command is run without the daemon running.
# Only run snap if the daemon is also running.
has snap && ps -e | grep -qFm 1 snapd >/dev/null && tot snap list && ((packages-=1))
has snap && ps -e | grep -qFm 1 snapd >/dev/null && \
pkgs_h=1 tot snap list && ((packages-=1))
# This is the only standard location for appimages.
# See: https://github.com/AppImage/AppImageKit/wiki
@ -1581,7 +1589,7 @@ get_packages() {
;;
"Mac OS X"|"macOS"|MINIX)
has port && tot port installed && ((packages-=1))
has port && pkgs_h=1 tot port installed && ((packages-=1))
has brew && dir /usr/local/Cellar/*
has pkgin && tot pkgin list
@ -1603,9 +1611,9 @@ get_packages() {
esac
# Scoop environment throws errors if `tot scoop list` is used
has scoop && dir ~/scoop/apps/* && ((packages-=1))
has scoop && pkgs_h=1 dir ~/scoop/apps/* && ((packages-=1))
# Count chocolatey packages.
# Count chocolatey packages.
[[ -d /cygdrive/c/ProgramData/chocolatey/lib ]] && \
dir /cygdrive/c/ProgramData/chocolatey/lib/*
;;
@ -1613,11 +1621,11 @@ get_packages() {
Haiku)
has pkgman && dir /boot/system/package-links/*
packages=${packages/pkgman/depot}
;;
;;
IRIX)
manager=swpkg
tot versions -b && ((packages-=3))
pkgs_h=3 tot versions -b && ((packages-=3))
;;
esac