48 lines
930 B
Bash
Executable File
48 lines
930 B
Bash
Executable File
#!/bin/sh
|
|
|
|
_printhelp()
|
|
{
|
|
cat <<EOF
|
|
Usage: ${1##*/} [OPTIONS] PACKAGES
|
|
|
|
Display size of files in PACKAGES.
|
|
|
|
-h: Display this help.
|
|
-n: Sort by size.
|
|
|
|
EOF
|
|
}
|
|
|
|
OPTION_SORT="cat"
|
|
|
|
while getopts ":hn" opt; do
|
|
case $opt in
|
|
h)
|
|
_printhelp "$0"
|
|
exit 1 ;;
|
|
n)
|
|
OPTION_SORT="sort -h" ;;
|
|
?)
|
|
_printhelp "$0"
|
|
exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
if [ $# -eq 0 ]; then
|
|
echo "Missing argument."
|
|
_printhelp "$0"
|
|
exit 1
|
|
fi
|
|
|
|
! command -v pacman >/dev/null && echo "You need pacman to run this script." && exit 1
|
|
if [ $(pacman -Qq "$@" 2>/dev/null | wc -l) -eq 0 ]; then
|
|
echo "No valid package given." >&2
|
|
exit
|
|
fi
|
|
|
|
## We use "eval" to be compatible with non-POSIX wordsplitting (e.g. zsh).
|
|
## WARNING: this only works with GNU 'du'.
|
|
du -bch $(pacman -Qlq "$@" | grep -v '.*/$' | sort -u) 2>/dev/null | eval ${OPTION_SORT}
|