mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-23 00:08:50 -05:00
b1bb2eaa50
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
23 lines
365 B
Bash
23 lines
365 B
Bash
size_to_human() {
|
|
awk -v size="$1" '
|
|
BEGIN {
|
|
suffix[1] = "B"
|
|
suffix[2] = "KiB"
|
|
suffix[3] = "MiB"
|
|
suffix[4] = "GiB"
|
|
suffix[5] = "TiB"
|
|
suffix[6] = "PiB"
|
|
suffix[7] = "EiB"
|
|
count = 1
|
|
|
|
while (size > 1024) {
|
|
size /= 1024
|
|
count++
|
|
}
|
|
|
|
sizestr = sprintf("%.2f", size)
|
|
sub(/\.?0+$/, "", sizestr)
|
|
printf("%s %s", sizestr, suffix[count])
|
|
}'
|
|
}
|