Added a function for expressing file sizes in more reasonable terms.

dev
Emily Frost 5 years ago
parent d1a9a76687
commit 7bc0c823d0
Signed by: Emily
GPG Key ID: AA5D42849F1CBDC9

23
nyan

@ -9,6 +9,26 @@ if [ ! -e "$(which pv)" ]; then
exit 1 exit 1
fi fi
function simplify_size_number {
declare -i bytes=$1
declare -i kilobytes=$((bytes/1024))
size_str=""
if [ $kilobytes -lt 1024 ]; then
size_str="${kilobytes}kb"
else
declare -i megabytes=$((kilobytes/1024))
if [ $megabytes -lt 1024 ]; then
size_str="${megabytes}mb"
else
declare -i gigabytes=$((megabytes/1024))
size_str="${gigabytes}gb"
fi
fi
echo "$size_str"
}
while getopts ${optstring} args; do while getopts ${optstring} args; do
case $args in case $args in
o) output_file=${OPTARG} ;; o) output_file=${OPTARG} ;;
@ -30,8 +50,7 @@ for fname in "$@"; do
else else
current_file_size=$(stat -c%s "$fname") current_file_size=$(stat -c%s "$fname")
total_size=$((total_size+current_file_size)) total_size=$((total_size+current_file_size))
# TODO: Use something more legible than bytes. echo "Adding ${fname} at $(simplify_size_number $total_size)."
echo "Adding ${fname} at ${total_size}b."
fi fi
done done

Loading…
Cancel
Save