-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Option to show memory in GB #1170
Comments
In bash, our normal math operations don't really allow decimals so it'd require some hack (e.g. Maybe we can use both KiB, MiB, and GiB, but bits, bytes, and even TiB seems pointless unless there are someone out there that uses at least 1024GiB RAM. |
yeah some of them would be pointless, More or less just to give users more options, the most useful ones would be MiB, GiB and maybe KiB if you're running linux on an old computer. |
How about using this example to make it output like you want: 😉 #!/usr/bin/env bash
num=3000000
divider=1024
units="GiB"
precision=2
printf -v out "%'.*f %s" \
$precision \
$(($num / $divider)).$(($num % $divider)) \
$units
printf "out='%s'\n" "$out" gives out='2,929.70 GiB' |
How do I use that with the neofetch memory module though 🤔 |
We can do this: case "${mem_label:-$memory_format}" in
"GiB")
((mem_used=mem_used/1024))
((mem_total=mem_total/1024))
mem_label="GiB"
;;
"KiB")
((mem_used=mem_used*1024))
((mem_total=mem_total*1024))
mem_label="KiB"
;;
esac This ignores the conversion if |
We can also do this to "fake" it. # Use $mem_label if available.
case "${mem_label:-$memory_format}" in
"GiB")
mem_used="${mem_used:0:-3}.${mem_used/${mem_used:0:-2}}"
mem_total="${mem_total:0:-3}.${mem_total/${mem_total:0:-2}}"
mem_label="GiB"
;;
"KiB")
((mem_used=mem_used*1024))
((mem_total=mem_total*1024))
mem_label="KiB"
;;
esac |
Why not use case "${mem_label:-$memory_format}" in
"GiB")
mem_label="GiB"
divider=1024
precision=${mem_precision:-2}
printf -v mem_used "%'.*f" \
$precision \
$(($mem_used / $divider)).$(($mem_used % $divider))
printf -v mem_total "%'.*f" \
$precision \
$(($mem_total / $divider)).$(($mem_total % $divider))
;;
esac Keep in mind though for this functionality it would be much better when the orignal mem_xxx values are in bytes instead of being transformed into MB before this code... |
Neofetch almost never calls printf directly. It'll be taken care of in user's config (the For instance, neofetch (from user config) will fetch the |
printf in the way i use is not outputting anything to stdout/stderr, the |
This has been implemented. |
Someone ordered a 4TB computer from linustechtips, don't remember the video tho |
is there a way to make it show GB instead of GiB? |
Replace 1024 to 1000 in the code where needed and rebuild neofetch |
Improving dylanaraps@0435dcd - Implementing dylanaraps#1170 (comment) 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 dylanaraps#1170 (comment)
An option for the memory module that will let you show in more formats than MiB, maybe allow bits, bytes, KB, MB, GB, TB, with/without decimal place, and maybe an option for how many decimal places to show.
So instead of
3433MiB / 23974MiB
It could show3.4GiB / 24GiB
The text was updated successfully, but these errors were encountered: