Merge pull request #1015 from dylanaraps/pkgs

packages: refactor (List package managers used/cleanup)
This commit is contained in:
Dylan Araps 2018-06-02 21:52:38 +00:00 committed by GitHub
commit 159cf63658
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 79 additions and 104 deletions

View file

@ -13,7 +13,7 @@ script:
- time ./neofetch --travis -v
# See this wiki page for why we're disabling these errors.
# https://github.com/dylanaraps/neofetch/wiki/Shellcheck-Exclusions
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then shellcheck neofetch -e SC1090,SC2009,SC2012,SC2016,SC2034,SC2128,SC2153,SC2154,SC2178,SC2010,SC1004,SC1091,SC1117; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then shellcheck neofetch; fi
# The if statement is here to invert the exit code from grep.
# grep normally errors if no match is found but we want the opposite.
# We invert it so grep fails if a match is found.

178
neofetch
View file

@ -143,6 +143,21 @@ os_arch="on"
uptime_shorthand="on"
# Packages
# Show/Hide Package Manager names.
#
# Default: 'on'
# Values: 'on', 'off'
# Flag: --package_manager
#
# Example:
# on: '900 (pacman, apt)'
# off: '900'
package_manager="on"
# Shell
@ -1222,135 +1237,90 @@ get_uptime() {
}
get_packages() {
pkgs() { type -p "$1" >/dev/null && { ((packages+="$2"));(("$2">0))&&managers+="$_, "; }; }
tots() { IFS=$'\n' read -d "" -ra files < <($1); echo "${#files[@]}"; }
dirc() { echo $#; }
case "$os" in
"Linux" | "BSD" | "iPhone OS" | "Solaris")
type -p pacman-key >/dev/null && \
packages="$(pacman -Qq --color never | wc -l)"
pkgs "pacman-key" "$(tots "pacman -Qq --color never")"
pkgs "rpm" "$(tots "rpm -qa")"
pkgs "xbps-query" "$(tots "xbps-query -l")"
pkgs "apk" "$(tots "apk info")"
pkgs "opkg" "$(tots "opkg list-installed")"
pkgs "pacman-g2" "$(tots "pacman-g2 -Q")"
pkgs "lvu" "$(tots "lvu installed")"
pkgs "tce-status" "$(tots "tce-status -i")"
pkgs "pkg_info" "$(tots "pkg_info")"
pkgs "tazpkg" "$(tots "tazpkg list") - 6"
pkgs "sorcery" "$(tots "gaze installed")"
pkgs "alps" "$(tots "alps showinstalled")"
pkgs "butch" "$(tots "butch list")"
pkgs "emerge" "$(dirc /var/db/pkg/*/*/)"
pkgs "nix-env" "$(dirc /nix/store/*/)"
pkgs "guix" "$(dirc /gnu/store/*/)"
pkgs "Compile" "$(dirc /Programs/*/)"
pkgs "eopkg" "$(dirc /var/lib/eopkg/package/*)"
pkgs "crew" "$(dirc /usr/local/etc/crew/meta/*.filelist)"
pkgs "pkgtool" "$(dirc /var/log/packages/*)"
pkgs "cave" "$(dirc /var/db/paludis/repositories/cross-installed/*/data/*/ \
/var/db/paludis/repositories/installed/data/*/)"
pkgs "kpm-pkg" "$(kpm --get-selections | grep -cv deinstall$)"
pkgs "dpkg" "$(dpkg --get-selections | grep -cv deinstall$)"
type -p dpkg >/dev/null && \
((packages+=$(dpkg --get-selections | grep -cv deinstall$)))
case "$kernel_name" in
"FreeBSD") pkgs "pkg" "$(tots "pkg info")" ;;
"SunOS") pkgs "pkginfo" "$(tots "pkginfo -i")" ;;
type -p pkgtool >/dev/null && \
((packages+=$(ls -1 /var/log/packages | wc -l)))
*)
pkgs "pkg" "$(dirc /var/db/pkg/*)"
type -p rpm >/dev/null && \
((packages+=$(rpm -qa | wc -l)))
type -p xbps-query >/dev/null && \
((packages+=$(xbps-query -l | wc -l)))
[[ "$os" != "Linux" ]] && type -p pkginfo >/dev/null && \
((packages+=$(pkginfo -i | wc -l)))
type -p emerge >/dev/null && \
((packages+=$(ls -d /var/db/pkg/*/* | wc -l)))
type -p nix-env >/dev/null && \
((packages+=$(ls -d -1 /nix/store/*/ | wc -l)))
type -p guix >/dev/null && \
((packages+=$(ls -d -1 /gnu/store/*/ | wc -l)))
type -p apk >/dev/null && \
((packages+=$(apk info | wc -l)))
type -p opkg >/dev/null && \
((packages+=$(opkg list-installed | wc -l)))
type -p pacman-g2 >/dev/null && \
((packages+=$(pacman-g2 -Q | wc -l)))
type -p lvu >/dev/null && \
((packages+=$(lvu installed | wc -l)))
type -p tce-status >/dev/null && \
((packages+=$(tce-status -i | wc -l)))
type -p Compile >/dev/null && \
((packages+=$(ls -d -1 /Programs/*/ | wc -l)))
type -p eopkg >/dev/null && \
((packages+=$(ls -1 /var/lib/eopkg/package | wc -l)))
type -p pkg_info >/dev/null && \
((packages+=$(pkg_info | wc -l)))
type -p crew >/dev/null && \
((packages+=$(ls -l /usr/local/etc/crew/meta/*.filelist | wc -l)))
type -p tazpkg >/dev/null && \
((packages+=$(tazpkg list | wc -l) - 6))
type -p sorcery >/dev/null && \
((packages+=$(gaze installed | wc -l)))
type -p alps >/dev/null && \
((packages+=$(alps showinstalled | wc -l)))
type -p kpt >/dev/null && \
type -p kpm >/dev/null && \
((packages+=$(kpm --get-selections | grep -cv deinstall$)))
if type -p cave >/dev/null; then
package_dir=(/var/db/paludis/repositories/{cross-installed/*,installed}/data/*)
((packages+=$(ls -d -1 "${package_dir[@]}" | wc -l)))
fi
type -p butch >/dev/null && \
((packages+=$(butch list | wc -l)))
if type -p pkg >/dev/null; then
case "$kernel_name" in
"FreeBSD") ((packages+=$(pkg info | wc -l))) ;;
*)
((packages+=$(ls -1 /var/db/pkg | wc -l)))
((packages == 0)) && ((packages+=$(pkg list | wc -l)))
esac
fi
((packages == 0)) && \
pkgs "pkg" "$(tots "pkg list")"
;;
esac
;;
"Mac OS X" | "MINIX")
type -p port >/dev/null && \
((packages+=$(port installed | wc -l) - 1))
pkgs "port" "$(tots "port installed") - 1"
pkgs "brew" "$(dirc /usr/local/Cellar/*) - 1"
pkgs "pkgin" "$(tots "pkgin list")"
;;
type -p brew >/dev/null && \
((packages+=$(find /usr/local/Cellar -maxdepth 1 | wc -l) - 1))
type -p pkgin >/dev/null && \
((packages+=$(pkgin list | wc -l)))
"AIX"| "FreeMiNT")
pkgs "lslpp" "$(lslpp -J -l -q | grep -cv '^#')"
pkgs "rpm" "$(tots "rpm -qa")"
;;
"Windows")
case "$kernel_name" in
"CYGWIN"*) packages="$(cygcheck -cd | wc -l)" ;;
"MSYS"*) packages="$(pacman -Qq --color never | wc -l)"
"CYGWIN"*) pkgs "cygcheck" "$(tots "cygcheck -cd")" ;;
"MSYS"*) pkgs "pacman" "$(tots "pacman -Qq --color never")" ;;
esac
# Count chocolatey packages.
[[ -d "/cygdrive/c/ProgramData/chocolatey/lib" ]] && \
((packages+=$(ls -1 /cygdrive/c/ProgramData/chocolatey/lib | wc -l)))
pkgs ":" "$(dirc /cygdrive/c/ProgramData/chocolatey/lib/*)"
;;
"Haiku")
packages="$(ls -1 /boot/system/package-links | wc -l)"
;;
"AIX")
packages="$(lslpp -J -l -q | grep -cv '^#')"
((packages+=$(rpm -qa | wc -l)))
files=(/boot/system/package-links/*)
packages="${#files[@]}"
;;
"IRIX")
packages="$(($(versions -b | wc -l)-3))"
;;
"FreeMiNT")
type -p rpm >/dev/null && \
packages="$(rpm -qa | wc -l)"
packages="$(($(tots "versions -b")-3))"
;;
esac
((packages == 0)) && unset packages
if ((packages == 0)); then
unset packages
elif [[ "$package_manager" == "on" && "${managers//,}" ]]; then
managers="${managers/pacman-key/pacman}"
managers="${managers/kpt-pkg/kpt}"
packages+=" (${managers%,*})"
fi
}
get_shell() {
@ -4246,6 +4216,7 @@ INFO:
NOTE: You can supply multiple args. eg. 'neofetch --disable cpu gpu'
--package_manager on/off Hide/Show Package Manager names.
--os_arch on/off Hide/Show OS architecture.
--speed_type type Change the type of cpu speed to display.
Possible values: current, min, max, bios,
@ -4438,6 +4409,7 @@ get_args() {
while [[ "$1" ]]; do
case "$1" in
# Info
"--package_manager") package_manager="$2" ;;
"--os_arch") os_arch="$2" ;;
"--cpu_cores") cpu_cores="$2" ;;
"--cpu_speed") cpu_speed="$2" ;;

View file

@ -22,6 +22,9 @@ For example: 'info "Memory" memory' would be '\-\-disable memory'
.IP
NOTE: You can supply multiple args. eg. 'neofetch \fB\-\-disable\fR cpu gpu'
.TP
\fB\-\-package_manager\fR on/off
Hide/Show Package Manager names.
.TP
\fB\-\-os_arch\fR on/off
Hide/Show OS architecture.
.TP