Add --package_minimal

Reduces 'packages' output by omitting language package managers and Steam games, improving execution speed
This commit is contained in:
OpenSauce04 2024-04-30 13:16:49 +00:00
parent 51f0ebf3ea
commit 3a415600d5

View file

@ -235,6 +235,15 @@ package_managers="on"
# off: '17 packages (flatpak)' # off: '17 packages (flatpak)'
package_separate="on" package_separate="on"
# Reduce output of packages list by not showing programming language package managers or Steam games
#
# Flag: --package_minimal
#
# Example:
# default: 'Packages: 1 (npm), 991 (emerge), 3 (steam), 23 (flatpak-system)'
# minimal: 'Packages: 991 (emerge), 23 (flatpak-system)'
package_minimal=""
# Shell # Shell
@ -2066,28 +2075,29 @@ get_packages() {
} }
} }
# OS-independent package managers. # Programming language package managers.
has pipx && tot pipx list --short if [[ -z "$package_minimal" ]]; then
has cargo && _cargopkgs="$(cargo install --list | grep -v '^ ')" && tot echo "$_cargopkgs" has pipx && tot pipx list --short
has am && pac "$(am -f --less)" has cargo && _cargopkgs="$(cargo install --list | grep -v '^ ')" && tot echo "$_cargopkgs"
# Special case for npm: If has npm, we should list folders under node_modules instead of using npm list. # Special case for npm: If has npm, we should list folders under node_modules instead of using npm list.
# This is because npm list is very slow (2s) # This is because npm list is very slow (2s)
if has npm; then if has npm; then
# Try to apply heuristics to find the global directory. # Try to apply heuristics to find the global directory.
if [[ -d /usr/lib/node_modules ]]; then if [[ -d /usr/lib/node_modules ]]; then
dir /usr/lib/node_modules/*/ dir /usr/lib/node_modules/*/
elif [[ -d /usr/local/lib/node_modules ]]; then elif [[ -d /usr/local/lib/node_modules ]]; then
dir /usr/local/lib/node_modules/*/ dir /usr/local/lib/node_modules/*/
else else
# If neither exist, use npm root -g to get the global directory. # If neither exist, use npm root -g to get the global directory.
# (still ~10x faster than npm list) # (still ~10x faster than npm list)
npm_global=$(npm root -g) npm_global=$(npm root -g)
[[ -d $npm_global ]] && dir "$npm_global"/*/ [[ -d $npm_global ]] && dir "$npm_global"/*/
# This may not work in WSL2 (if npm is installed on Windows, not WSL). # This may not work in WSL2 (if npm is installed on Windows, not WSL).
# However, if npm is not installed on this WSL subsystem, it doesn't really count # However, if npm is not installed on this WSL subsystem, it doesn't really count
# as a package manager for this subsystem, so let's ignore this case. # as a package manager for this subsystem, so let's ignore this case.
fi
fi fi
fi fi
@ -2121,6 +2131,7 @@ get_packages() {
has squirrel && tot ls /var/packages has squirrel && tot ls /var/packages
has pkgx && tot find "$HOME/.pkgx" -maxdepth 2 -mindepth 2 -type d has pkgx && tot find "$HOME/.pkgx" -maxdepth 2 -mindepth 2 -type d
has anise && tot anise s --installed has anise && tot anise s --installed
has am && pac "$(am -f --less)"
# Using the dnf package cache is much faster than rpm. # Using the dnf package cache is much faster than rpm.
if has dnf && type -p sqlite3 >/dev/null && [[ -f /var/cache/dnf/packages.db ]]; then if has dnf && type -p sqlite3 >/dev/null && [[ -f /var/cache/dnf/packages.db ]]; then
@ -2155,14 +2166,16 @@ get_packages() {
shopt -u nullglob shopt -u nullglob
} }
# Steam games if [[ -z "$package_minimal" ]]; then
STEAM_P=".local/share/Steam/steamapps/common" # Steam games
if [[ -d "$HOME/$STEAM_P" ]]; then STEAM_P=".local/share/Steam/steamapps/common"
manager=steam && dir "$HOME/$STEAM_P/*/" if [[ -d "$HOME/$STEAM_P" ]]; then
elif [[ -d "$HOME/.var/app/com.valvesoftware.Steam/$STEAM_P" ]]; then manager=steam && dir "$HOME/$STEAM_P/*/"
manager=steam && dir "$HOME/.var/app/com.valvesoftware.Steam/$STEAM_P/*/" elif [[ -d "$HOME/.var/app/com.valvesoftware.Steam/$STEAM_P" ]]; then
elif [[ -d "$HOME/.steam/steam/steamapps/common" ]]; then manager=steam && dir "$HOME/.var/app/com.valvesoftware.Steam/$STEAM_P/*/"
manager=steam && dir "$HOME/.steam/steam/steamapps/common/*/" elif [[ -d "$HOME/.steam/steam/steamapps/common" ]]; then
manager=steam && dir "$HOME/.steam/steam/steamapps/common/*/"
fi
fi fi
# Other (Needs complex command) # Other (Needs complex command)
@ -6368,6 +6381,7 @@ INFO:
--title_fqdn on/off Hide/Show Fully Qualified Domain Name in title. --title_fqdn on/off Hide/Show Fully Qualified Domain Name in title.
--package_managers on/off Hide/Show Package Manager names. (on, tiny, off) --package_managers on/off Hide/Show Package Manager names. (on, tiny, off)
--package_separate on/off Whether to separate system/user modes for supported package managers --package_separate on/off Whether to separate system/user modes for supported package managers
--package_minimal Reduce output of packages list by not showing programming language package managers or Steam games
--os_arch on/off Hide/Show OS architecture. --os_arch on/off Hide/Show OS architecture.
--speed_type type Change the type of cpu speed to display. --speed_type type Change the type of cpu speed to display.
Possible values: current, min, max, bios, Possible values: current, min, max, bios,
@ -6637,6 +6651,7 @@ get_args() {
"--title_fqdn") title_fqdn="$2" ;; "--title_fqdn") title_fqdn="$2" ;;
"--package_managers") package_managers="$2" ;; "--package_managers") package_managers="$2" ;;
"--package_separate") package_separate="$2" ;; "--package_separate") package_separate="$2" ;;
"--package_minimal") package_minimal="1" ;;
"--os_arch") os_arch="$2" ;; "--os_arch") os_arch="$2" ;;
"--cpu_cores") cpu_cores="$2" ;; "--cpu_cores") cpu_cores="$2" ;;
"--cpu_speed") cpu_speed="$2" ;; "--cpu_speed") cpu_speed="$2" ;;