diff options
Diffstat (limited to '.config/init/funcs/b2h')
-rwxr-xr-x | .config/init/funcs/b2h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/.config/init/funcs/b2h b/.config/init/funcs/b2h new file mode 100755 index 0000000..3a8d15a --- /dev/null +++ b/.config/init/funcs/b2h @@ -0,0 +1,14 @@ +#!/usr/bin/env zsh +# convert bits to human-readable value + +local suffixes=( 'B' 'K' 'M' 'G' 'T' 'P' 'E' 'Z' 'Y' ) +local sindex=1 +local val=$1 +[[ -z $(echo $1 | grep "^[0-9]*$") ]] && read val + +while [[ $(echo $val / 1024 | bc) -ne 0 ]]; do + val=$(echo "scale=2; $val / 1024" | bc) + let sindex=sindex+1 +done + +echo "${val}${suffixes[$sindex]}" |