From 6f69588d786acce5f93582966ecd2ddee9a5d6eb Mon Sep 17 00:00:00 2001 From: aristocratos Date: Fri, 12 Jun 2020 16:09:54 +0200 Subject: [PATCH] Fixed humanizer function by rounding values 1000-1023 up to 1024 to fit. --- bashtop | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bashtop b/bashtop index 81260fe..e3977bc 100755 --- a/bashtop +++ b/bashtop @@ -852,10 +852,11 @@ floating_humanizer() { #? Convert integer to floating point and scale up in ste until ((${#value}<6)); do value=$((value>>10)) + if ((value<100)); then value=100; fi ((++selector)) done - if [[ -z $short ]] && ((${#value}<5 & ${#value}>=2 & selector>0)); then + if ((${#value}<5 & ${#value}>=2 & selector>0)); then decimals=$((5-${#value})) value="${value::-2}.${value:(-${decimals})}" elif ((${#value}>=2)); then @@ -863,6 +864,8 @@ floating_humanizer() { #? Convert integer to floating point and scale up in ste fi fi + if [[ -n $short ]]; then value="${value%.*}"; fi + out_var="${value}${sep}${unit[$selector]::${short:-${#unit[$selector]}}}${per_second}" if [[ -z $ext_var ]]; then echo -n "${out_var}"; fi } @@ -4814,6 +4817,9 @@ if [[ $use_psutil == true ]]; then fi fi +#* if we have been sourced by another shell, quit. Allows sourcing only function definition. +[[ "${#BASH_SOURCE[@]}" -gt 1 ]] && { return 0; } + #* Set up traps for ctrl-c, soft kill, window resize, ctrl-z and resume from ctrl-z trap 'quitting=1; time_left=0' SIGINT SIGQUIT SIGTERM trap 'resized=1; time_left=0' SIGWINCH @@ -4842,10 +4848,6 @@ else exec 2>/dev/null fi - -#* if we have been sourced by another shell, quit. Allows sourcing only function definition. -[[ "${#BASH_SOURCE[@]}" -gt 1 ]] && { return 0; } - #* Call init function init_