From 67cf02c964106b08fcb2ba50c0e5d0a11d10c54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=A9TriMoon=E2=84=A2?= Date: Mon, 31 Oct 2022 13:03:10 +0300 Subject: [PATCH] Enhancing --memory_unit functionality Improving https://github.com/dylanaraps/neofetch/commit/0435dcd0cd44bb22afa9b986f15742cc05de7b20 - Implementing https://github.com/dylanaraps/neofetch/issues/1170#issuecomment-455576889 to avoid awk usage. - Adding ability to configure precision of output using `mem_precision` which defaults to `2`. - Added `tib` to accommodate TiB mentioned in https://github.com/dylanaraps/neofetch/issues/1170#issuecomment-894705941 --- neofetch | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index 48b96d21..006d2d40 100755 --- a/neofetch +++ b/neofetch @@ -2802,10 +2802,26 @@ get_memory() { [[ "$memory_percent" == "on" ]] && ((mem_perc=mem_used * 100 / mem_total)) case $memory_unit in + tib) + mem_label=TiB + memory_unit_divider=$((1024 * 1024)) + printf -v mem_used "%'.*f" \ + ${mem_precision:-2} \ + $(($mem_used / $memory_unit_divider)).$(($mem_used % $memory_unit_divider)) + printf -v mem_total "%'.*f" \ + ${mem_precision:-2} \ + $(($mem_total / $memory_unit_divider)).$(($mem_total % $memory_unit_divider)) + ;; + gib) - mem_used=$(awk '{printf "%.2f", $1 / $2}' <<< "$mem_used 1024") - mem_total=$(awk '{printf "%.2f", $1 / $2}' <<< "$mem_total 1024") mem_label=GiB + memory_unit_divider=1024 + printf -v mem_used "%'.*f" \ + ${mem_precision:-2} \ + $(($mem_used / $memory_unit_divider)).$(($mem_used % $memory_unit_divider)) + printf -v mem_total "%'.*f" \ + ${mem_precision:-2} \ + $(($mem_total / $memory_unit_divider)).$(($mem_total % $memory_unit_divider)) ;; kib)