Update neofetch

Making calculations general purpose.
This commit is contained in:
©TriMoon™ 2022-10-31 14:29:18 +03:00 committed by GitHub
parent d57463b0d3
commit 619c9d2224
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2807,6 +2807,9 @@ get_memory() {
[[ "$memory_percent" == "on" ]] && ((mem_perc=mem_used * 100 / mem_total)) [[ "$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 case $memory_unit in
tib) tib)
mem_label=TiB mem_label=TiB
@ -2820,24 +2823,21 @@ get_memory() {
kib) kib)
mem_label=KiB mem_label=KiB
memory_unit_multiplier=1024
;; ;;
esac esac
# Uses temp variables from above: memory_unit_divider, memory_unit_multiplier
case $mem_label in if test "$memory_unit_divider" -ge 1; then
GiB|TiB)
printf -v mem_used "%'.*f" \ printf -v mem_used "%'.*f" \
"${mem_precision}" \ "${mem_precision}" \
$((mem_used / memory_unit_divider)).$((mem_used % memory_unit_divider)) $((mem_used / memory_unit_divider)).$((mem_used % memory_unit_divider))
printf -v mem_total "%'.*f" \ printf -v mem_total "%'.*f" \
"${mem_precision}" \ "${mem_precision}" \
$((mem_total / memory_unit_divider)).$((mem_total % memory_unit_divider)) $((mem_total / memory_unit_divider)).$((mem_total % memory_unit_divider))
;; elif test "$memory_unit_multiplier" -ge 1; then
mem_used=$((mem_used * memory_unit_multiplier))
KiB) mem_total=$((mem_total * memory_unit_multiplier))
mem_used=$((mem_used * 1024)) fi
mem_total=$((mem_total * 1024))
;;
esac
memory="${mem_used}${mem_label:-MiB} / ${mem_total}${mem_label:-MiB} ${mem_perc:+(${mem_perc}%)}" memory="${mem_used}${mem_label:-MiB} / ${mem_total}${mem_label:-MiB} ${mem_perc:+(${mem_perc}%)}"