3 # Copyright © 2009 Nick Bowler
5 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
6 # This is free software: you are free to do what the fuck you want to.
7 # There is NO WARRANTY, to the extent permitted by law.
10 while getopts 's' opt $@; do
19 if [[ $# == 0 ]]; then
20 printf 'usage: %s [-s] directory [directory ...]\n' $0
24 # Normalize target names.
33 # Simple wrapper around find to search for ordinary files in the target
36 find $targets -type f $@
39 # Simple ngettext wrapper that should work even if ngettext is not installed.
41 command ngettext $@ 2>/dev/null && return 0;
43 while [[ $# -gt 3 ]]; do shift; done
45 1) printf '%s\n' "$1" ;;
46 *) printf '%s\n' "$2" ;;
50 # Get the total size (in mebibytes) of a list of files specified on standard
51 # input. The input is expected to be in the format of find -print0.
53 du -mc --files0-from=- | sed -n '$s/\ttotal$//p'
54 (exit ${${pipestatus%0}[1]})
57 formats=(flac flac ogg vorbis opus opus mp3 mp3)
59 for ext name in $formats; do
60 typeset $ext=`mfind -name \*.$ext | wc -l`
61 total=$((total + $ext))
64 if [[ $total == 0 ]]; then
69 printf '%d %s in %d %s' "$total" `ngettext track tracks $total` \
70 "$#" `ngettext directory directories $#`
74 float totalsize=`mfind -print0 | getsize`
75 if [[ $totalsize -gt 4000 ]]; then
76 printf '(%.1fGiB total disk usage)' $((totalsize/1024))
78 printf '(%.1fMiB total disk usage)' $((totalsize))
83 for ext name in $formats; do
84 printf ' %*d %5.1f%% %s' $#total $(($ext)) \
85 $((100.0*$ext/total)) $name
88 printf '%*s' $((8-$#name))
90 float size=`mfind -name \*.$ext -print0 | getsize`
91 if [[ $totalsize -gt 4000 ]]; then
92 integer t=$((totalsize/1024))
93 printf '(%*.1fGiB)' $(($#t+2)) $((size/1024))
95 integer t=$((totalsize))
96 printf '(%*.1fMiB)' $(($#t+2)) $((size))