Skip to content

Commit

Permalink
[PR] dylanaraps/neofetch#2225 from TriMoon - Enhancing --memory_unit …
Browse files Browse the repository at this point in the history
…functionality

Upstream PR: dylanaraps/neofetch#2225
Thanks to @TriMoon

Co-authored-by: ©TriMoon™ <TriMoon@users.noreply.github.com>
  • Loading branch information
hykilpikonna and TriMoon committed Oct 31, 2022
2 parents 8616ff0 + 67cf02c commit 3d6427b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions neofetch
Original file line number Diff line number Diff line change
Expand Up @@ -3229,10 +3229,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 "%.1f", $1 / $2}' <<< "$mem_used 1024")
mem_total=$(awk '{printf "%.1f", $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)
Expand Down

0 comments on commit 3d6427b

Please sign in to comment.