ambevar-dotfiles/.scripts/pacfiles

47 lines
821 B
Plaintext
Raw Normal View History

#!/bin/sh
_usage () {
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)
_usage "$0"
exit 1 ;;
n)
OPTION_SORT="sort -h" ;;
\?)
_usage "$0"
exit 1 ;;
esac
done
shift $(($OPTIND - 1))
if [ $# -eq 0 ]; then
echo "Missing argument."
_usage "$0"
exit 1
fi
! command -v pacman >/dev/null && echo "You need pacman to run this script." && exit 1
2013-10-29 21:49:48 +01:00
if [ $(pacman -Qq "$@" 2>/dev/null | wc -l) -eq 0 ]; then
echo "No valid package given." >&2
exit
2013-10-29 21:49:48 +01:00
fi
2013-10-25 13:44:07 +02:00
## We use "eval" to be compatible with non-POSIX wordsplitting (e.g. zsh).
2014-02-03 17:51:06 +01:00
## WARNING: this only works with GNU 'du'.
2014-01-26 10:32:30 +01:00
du -bch $(pacman -Qlq "$@" | grep -v '.*/$' | sort -u) 2>/dev/null | eval ${OPTION_SORT}