#!/bin/sh _printhelp() { cat <&2 && exit 1 fi if [ $(pacman -Qq "$@" 2>/dev/null | wc -l) -eq 0 ]; then echo "No valid package given." >&2 exit fi ## We use external variable for awk to fit current locales. ## We use "eval" to be compatible with non-POSIX wordsplitting (e.g. zsh). RESULT="$(${CMD} $@ | awk -F "$SEP" -v filter="$pacman_size" -v pkg="$pacman_name" \ '$0 ~ pkg {pkgname=$2} $0 ~ filter {gsub(/\..*/,"") ; printf("%6s KiB %s\n", $2, pkgname)}' | sort -uk3 | eval $OPT_SORTN)" echo "$RESULT" ## Print total size. echo "$RESULT" | awk '{TOTAL=$1+TOTAL} END {printf("Total: %d KiB\n",TOTAL)}' ## One line version. Approximately same performance. Note the combination of ## 'tee' and >(awk ...) to write the detailed list to standard output and to ## pass it to awk. # ${CMD} $@ 2>/dev/null | awk -F "$SEP" -v filter="$pacman_size" -v pkg="$pacman_name" \ # '$0 ~ pkg {pkgname=$2} $0 ~ filter {gsub(/\..*/,"") ; printf("%6s KiB %s\n", $2, pkgname)}' | sort -u -k3 \ # | tee >(awk '{TOTAL=$1+TOTAL} END {printf("Total: %d KiB\n",TOTAL)}')