#!/bin/sh # pacsize -- display package sizes # # Copyright (C) 2014 Pierre Neidhardt # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . ################################################################################ ## Helper functions. calc_total () { awk '{ total += $1 print } END { printf ("%7s KIB TOTAL\n", total) }' } remove_duplicates () { awk '! table[$0]++' } usage() { cat <&2 usage "$0" exit 1 fi if ! command -v pacman >/dev/null 2>&1; then echo "'pacman' not found." >&2 exit 1 fi ## Locale. LC_NAME="$(gettext pacman "Name")" LC_SIZE="$(gettext pacman "Installed Size :" | sed 's/ *: *$//')" ## We use external variable for awk to fit current locales. In the following ## command, we strip the decimals. This makes output lighter. pacman -${db}i "$@" 2>/dev/null | awk -F ": " \ -v pkgsize="$LC_SIZE" -v pkgname="$LC_NAME" \ '$0 ~ pkgname { pkg = $2 } $0 ~ pkgsize { gsub (/[\.,].*/, "") printf ("%7s KiB %s\n", $2, pkg) }' | ($opt_sort || remove_duplicates) | ($opt_total || cat)