master zs
 1#!/bin/sh -eu
 2
 3# ripped from kiss-community/kiss/contrib/kiss-size lol
 4
 5get_size() {
 6    # Naive function to convert bytes to human readable
 7    # sizes (MB, KB, etc). This is probably wrong in places
 8    # though we can fix this over time. It's a start.
 9    case ${#1} in
10        [0-3]) hum=$(($1))KB ;;
11        [4-6]) hum=$(($1 / 1024))MB ;;
12        [7-9]) hum=$(($1 / 1024 / 1024))GB ;;
13        *)     hum=$(($1))  ;;
14    esac
15
16    printf '%s\t%s\n' "$hum" "$2"
17}
18
19du -sk `dtr pm $1` |
20    while read -r size file || {
21    get_size "$tot" total >&2
22    break
23} do
24    get_size "$size" "$file"
25    tot=$((tot + size))
26done