#!/usr/bin/env zsh # # Copyright © 2009 Nick Bowler # # License WTFPL2: Do What The Fuck You Want To Public License, version 2. # This is free software: you are free to do what the fuck you want to. # There is NO WARRANTY, to the extent permitted by law. sizes=0 while getopts 's' opt $@; do case $opt in s) sizes=1 ;; \?) exit 1 ;; esac done shift $((OPTIND-1)) if [[ $# == 0 ]]; then printf 'usage: %s [-s] directory [directory ...]\n' $0 exit 1 fi alias mfind='find $@ -type f' flac=`mfind -name '*.flac' | wc -l` vorbis=`mfind -name '*.ogg' | wc -l` mp3=`mfind -name '*.mp3' | wc -l` total=$((flac+vorbis+mp3)) if [[ $total == 0 ]]; then printf '0 tracks.\n' exit fi printf '%d tracks: %d (%.1f%%) flac, %d (%.1f%%) vorbis, %d (%.1f%%) mp3.\n' \ $total \ $flac $((100.0*flac /total)) \ $vorbis $((100.0*vorbis/total)) \ $mp3 $((100.0*mp3 /total)) if [[ $sizes == 1 ]]; then alias getsize="du -mc --files0-from=- | sed -n '\$s/\ttotal$//p'" float totalsize=`mfind -print0 | getsize` float flacsize=`mfind -name '*.flac' -print0 | getsize` float vorbissize=`mfind -name '*.ogg' -print0 | getsize` float mp3size=`mfind -name '*.mp3' -print0 | getsize` if [[ $totalsize -gt 4000 ]]; then printf 'size: %.1fG total, %.1fG flac, %.1fG vorbis, %.1fG mp3.\n' \ $((totalsize/1024)) \ $((flacsize/1024)) \ $((vorbissize/1024)) \ $((mp3size/1024)) else printf 'size: %.1fM total, %.1fM flac, %.1fM vorbis, %.1fM mp3.\n' \ $((totalsize)) \ $((flacsize)) \ $((vorbissize)) \ $((mp3size)) fi fi