3 # pacsysclean - Sort installed packages by increasing installed size. Useful for system clean-up.
5 declare -r myname
='pacsysclean'
6 declare -r myver
='@PACKAGE_VERSION@'
11 echo "$myname - Sort installed packages by increasing installed size."
13 echo "Usage: $myname [options]"
16 echo " -o <options> Specify custom pacman query options (e.g., dt)"
17 echo " -h, --help Show this help message and exit"
21 printf "%s %s\n" "$myname" "$myver"
22 echo 'Copyright (C) 2011 Eric BĂ©langer <snowmaniscool@gmail.com>'
28 -o) PACMAN_OPTS
="${2}" ;;
29 -h|
--help) usage
; exit 0 ;;
30 -V|
--version) version
; exit 0 ;;
37 size
="^Installed Size.*: (.*) KiB$"
39 [[ $PACMAN_OPTS && $PACMAN_OPTS != -* ]] && PACMAN_OPTS
="-$PACMAN_OPTS"
41 for line
in $
(LANG
=C pacman
-Qi $PACMAN_OPTS); do
42 if [[ $line =~
$name ]]; then
43 printf "%s\t" ${BASH_REMATCH[1]}
44 elif [[ $line =~
$size ]]; then
45 printf "%s\n" ${BASH_REMATCH[1]}
47 done |
sort -g -k2 |
awk '
49 split("KiB MiB GiB TiB PiB EiB ZiB YiB", suffix)
51 function format_size(size) {
53 while (size + 0 > 1024) {
57 sizestr = sprintf("%.2f %s", size, suffix[count])
61 printf("%s\t%s\n", format_size($2), $1);
64 # vim: set ts=2 sw=2 noet: