From 619c9d222438bf40a557558ca35e453f62955280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=A9TriMoon=E2=84=A2?= Date: Mon, 31 Oct 2022 14:29:18 +0300 Subject: [PATCH] Update neofetch Making calculations general purpose. --- neofetch | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/neofetch b/neofetch index 3618dd57..e487f8d9 100755 --- a/neofetch +++ b/neofetch @@ -2807,6 +2807,9 @@ get_memory() { [[ "$memory_percent" == "on" ]] && ((mem_perc=mem_used * 100 / mem_total)) + # Creates temp variables: memory_unit_divider, memory_unit_multiplier + memory_unit_divider=1 + memory_unit_multiplier=1 case $memory_unit in tib) mem_label=TiB @@ -2820,24 +2823,21 @@ get_memory() { kib) mem_label=KiB + memory_unit_multiplier=1024 ;; esac - - case $mem_label in - GiB|TiB) + # Uses temp variables from above: memory_unit_divider, memory_unit_multiplier + if test "$memory_unit_divider" -ge 1; then printf -v mem_used "%'.*f" \ "${mem_precision}" \ $((mem_used / memory_unit_divider)).$((mem_used % memory_unit_divider)) printf -v mem_total "%'.*f" \ "${mem_precision}" \ $((mem_total / memory_unit_divider)).$((mem_total % memory_unit_divider)) - ;; - - KiB) - mem_used=$((mem_used * 1024)) - mem_total=$((mem_total * 1024)) - ;; - esac + elif test "$memory_unit_multiplier" -ge 1; then + mem_used=$((mem_used * memory_unit_multiplier)) + mem_total=$((mem_total * memory_unit_multiplier)) + fi memory="${mem_used}${mem_label:-MiB} / ${mem_total}${mem_label:-MiB} ${mem_perc:+(${mem_perc}%)}"