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
1 changed files with 19 additions and 11 deletions

View File

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