tmoved human to full program: http://git.z3bra.org/cgit.cgi/human - scripts - various script and utils
(HTM) git clone git://z3bra.org/scripts
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) commit 2d3f871ea5a90ae67f297c968646eb64e03e7c56
(DIR) parent 432bfe1d4d7981ddcd9f4f05c3bd9ac37331b8be
(HTM) Author: z3bra <willy@mailoo.org>
Date: Tue, 4 Nov 2014 00:12:20 +0100
moved human to full program: http://git.z3bra.org/cgit.cgi/human
Diffstat:
D human | 67 -------------------------------
1 file changed, 0 insertions(+), 67 deletions(-)
---
(DIR) diff --git a/human b/human
t@@ -1,67 +0,0 @@
-#!/bin/sh
-#
-# z3bra - (c) wtfpl 2014
-
-usage () {
- cat <<EOF
-usage: `basename $0` [-hfbmgt] <number>
- -h : print help
- -f : detect best factorisation to use (default)
- -b : force output in Bytes
- -m : force output in Mio
- -g : force output in Gio
- -t : force output in Tio
-
-environment:
- SCALE : set the number of decimals
-EOF
-}
-
-# choose the best factore depending on the number
-factorize () {
- if [ $1 -gt 1073741824 ]; then
- echo T
- elif [ $1 -gt 1048576 ]; then
- echo G
- elif [ $1 -gt 1024 ]; then
- echo M
- else
- echo B
- fi
-}
-
-# perform calculation depending on expected format
-humanize () {
-
- unit=$1
- num=$2
-
- case $unit in
- M) pow=1 ;;
- G) pow=2 ;;
- T) pow=3 ;;
- *) pow=0; unit= ;;
- esac
-
- num=`echo "scale=${SCALE}; ${num} / (1024 ^ ${pow})" | bc`
-
- echo "${num}${unit}"
-}
-
-# Set the default number of decimals
-SCALE=${SCALE:-0}
-
-case $1 in
- -h) usage;;
- -b) humanize B $2 ;;
- -m) humanize M $2 ;;
- -g) humanize G $2 ;;
- -t) humanize T $2 ;;
- *)
- # this script require at least one argument
- test $# -lt 1 && usage && exit 1
-
-
- humanize `factorize $1` $1
- ;;
- esac