diff --git a/lib/moi/util/format.elv b/lib/moi/util/format.elv index 65464f6..bc5d2e5 100644 --- a/lib/moi/util/format.elv +++ b/lib/moi/util/format.elv @@ -177,3 +177,27 @@ fn list {|&with-header=$true &csep=' ' &hsep='-' &recompute=$true props data| echo (line &sep=$csep $props $d) } $data } + +fn size {|size| + var u = 0 + var m = [ + &10=Kio + &20=Mio + &30=Gio + ] + while (< $u 30) { + var p = (math:pow 2 (+ $u 10)) + if (< $size $p) { + break + } + set u = (to-string (+ $u 10)) + } + if (== $u 0) { + put $size + } else { + var p = (math:pow 2 (+ $u 10)) + var e = (/ $size $p) + printf '%.1f%s' $e $m[$u] + } + +}