Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/scripts/library/size_to_human.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/library/size_to_human.sh')
-rw-r--r--scripts/library/size_to_human.sh20
1 files changed, 20 insertions, 0 deletions
diff --git a/scripts/library/size_to_human.sh b/scripts/library/size_to_human.sh
new file mode 100644
index 00000000..9c0f0de2
--- /dev/null
+++ b/scripts/library/size_to_human.sh
@@ -0,0 +1,20 @@
+size_to_human() {
+ awk -v size="$1" '
+ BEGIN {
+ suffix[1] = "B"
+ suffix[2] = "KiB"
+ suffix[3] = "MiB"
+ suffix[4] = "GiB"
+ suffix[5] = "TiB"
+ count = 1
+
+ while (size > 1024) {
+ size /= 1024
+ count++
+ }
+
+ sizestr = sprintf("%.2f", size)
+ sub(/\.?0+$/, "", sizestr)
+ printf("%s %s", sizestr, suffix[count])
+ }'
+}