2011-11-21 17:21:24 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
2012-02-16 00:56:29 -05:00
|
|
|
# pacsysclean - Sort installed packages by increasing installed size. Useful for system clean-up.
|
2011-11-21 17:21:24 -05:00
|
|
|
|
2011-12-12 16:36:57 -05:00
|
|
|
declare -r myname='pacsysclean'
|
|
|
|
declare -r myver='@PACKAGE_VERSION@'
|
|
|
|
|
2011-11-21 17:21:24 -05:00
|
|
|
PACMAN_OPTS=
|
|
|
|
|
|
|
|
usage() {
|
2013-11-08 02:53:33 -05:00
|
|
|
echo "${myname} (pacman) v${myver}"
|
2012-05-06 19:53:00 -04:00
|
|
|
echo
|
2013-11-08 02:53:33 -05:00
|
|
|
echo "Sort installed packages by increasing installed size. Useful for"
|
|
|
|
echo "system clean-up."
|
|
|
|
echo
|
|
|
|
echo "Usage: ${myname} [options]"
|
2012-05-06 19:53:00 -04:00
|
|
|
echo
|
|
|
|
echo "Options:"
|
|
|
|
echo " -o <options> Specify custom pacman query options (e.g., dt)"
|
|
|
|
echo " -h, --help Show this help message and exit"
|
2011-11-21 17:21:24 -05:00
|
|
|
}
|
|
|
|
|
2011-12-12 16:36:57 -05:00
|
|
|
version() {
|
2012-05-06 19:53:00 -04:00
|
|
|
printf "%s %s\n" "$myname" "$myver"
|
|
|
|
echo 'Copyright (C) 2011 Eric Bélanger <snowmaniscool@gmail.com>'
|
2011-12-12 16:36:57 -05:00
|
|
|
}
|
|
|
|
|
2011-11-21 17:21:24 -05:00
|
|
|
if [ -n "$1" ]; then
|
2012-05-06 19:53:00 -04:00
|
|
|
case "$1" in
|
|
|
|
-o) PACMAN_OPTS="${2}" ;;
|
|
|
|
-h|--help) usage; exit 0 ;;
|
|
|
|
-V|--version) version; exit 0 ;;
|
|
|
|
*) usage; exit 1 ;;
|
|
|
|
esac
|
2011-11-21 17:21:24 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
IFS=$'\n'
|
|
|
|
name="^Name.*: (.*)$"
|
|
|
|
size="^Installed Size.*: (.*) KiB$"
|
2012-02-16 00:56:29 -05:00
|
|
|
|
2012-05-06 19:49:43 -04:00
|
|
|
[[ $PACMAN_OPTS && $PACMAN_OPTS != -* ]] && PACMAN_OPTS="-$PACMAN_OPTS"
|
2012-02-16 00:56:29 -05:00
|
|
|
|
2011-11-21 17:21:24 -05:00
|
|
|
for line in $(LANG=C pacman -Qi $PACMAN_OPTS); do
|
2012-05-06 19:53:00 -04:00
|
|
|
if [[ $line =~ $name ]]; then
|
|
|
|
printf "%s\t" ${BASH_REMATCH[1]}
|
|
|
|
elif [[ $line =~ $size ]]; then
|
|
|
|
printf "%s\n" ${BASH_REMATCH[1]}
|
|
|
|
fi
|
2011-11-21 17:21:24 -05:00
|
|
|
done | sort -g -k2 | awk '
|
|
|
|
BEGIN {
|
2012-05-06 19:53:00 -04:00
|
|
|
split("KiB MiB GiB TiB PiB EiB ZiB YiB", suffix)
|
2011-11-21 17:21:24 -05:00
|
|
|
}
|
|
|
|
function format_size(size) {
|
2012-05-06 19:53:00 -04:00
|
|
|
count = 1
|
|
|
|
while (size + 0 > 1024) {
|
|
|
|
size /= 1024
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
sizestr = sprintf("%.2f %s", size, suffix[count])
|
|
|
|
return sizestr
|
2011-11-21 17:21:24 -05:00
|
|
|
}
|
|
|
|
{
|
2012-05-06 19:53:00 -04:00
|
|
|
printf("%s\t%s\n", format_size($2), $1);
|
2011-11-21 17:21:24 -05:00
|
|
|
}'
|
2012-05-06 19:53:00 -04:00
|
|
|
|
2014-01-22 18:06:11 -05:00
|
|
|
# vim: set noet:
|