pactest: conflict between directory and a file
[pacman-ng.git] / contrib / pacsysclean.sh.in
blob37219ab525c9ac250b47460cf9b984daaa45ce00
1 #!/bin/bash
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@'
8 PACMAN_OPTS=
10 usage() {
11 echo "$myname - Sort installed packages by increasing installed size."
12 echo
13 echo "Usage: $myname [options]"
14 echo
15 echo "Options:"
16 echo " -o <options> Specify custom pacman query options (e.g., dt)"
17 echo " -h, --help Show this help message and exit"
20 version() {
21 printf "%s %s\n" "$myname" "$myver"
22 echo 'Copyright (C) 2011 Eric BĂ©langer <snowmaniscool@gmail.com>'
26 if [ -n "$1" ]; then
27 case "$1" in
28 -o) PACMAN_OPTS="${2}" ;;
29 -h|--help) usage; exit 0 ;;
30 -V|--version) version; exit 0 ;;
31 *) usage; exit 1 ;;
32 esac
35 IFS=$'\n'
36 name="^Name.*: (.*)$"
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 '
48 BEGIN {
49 split("KiB MiB GiB TiB PiB EiB ZiB YiB", suffix)
51 function format_size(size) {
52 count = 1
53 while (size + 0 > 1024) {
54 size /= 1024
55 count++
57 sizestr = sprintf("%.2f %s", size, suffix[count])
58 return sizestr
61 printf("%s\t%s\n", format_size($2), $1);
64 # vim: set ts=2 sw=2 noet: