Skip to content

Commit c71daaa

Browse files
Shaun Princeclaude
andcommitted
feat: Add memory_precision config option (partial #491)
Add configurable decimal precision for memory values: - New config option: memory_precision (default: 0) - New flag: --memory_precision 0-3 - Works with all memory_unit modes (kib, mib, gib) Examples: - precision=0: '10961MiB / 16384MiB' (default, backwards compatible) - precision=2: '10703.00MiB / 16384.00MiB' - gib + precision=2: '10.17GiB / 16.00GiB' Note: Disk precision requires more invasive changes since disk uses df -h output directly. Will be addressed separately. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c674552 commit c71daaa

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

neofetch

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,19 @@ memory_percent="off"
183183
# gib: ' 0.98GiB / 6.79GiB'
184184
memory_unit="mib"
185185
186+
# Memory precision
187+
#
188+
# Decimal places for memory values.
189+
#
190+
# Default: '0'
191+
# Values: '0', '1', '2', '3'
192+
# Flag: --memory_precision
193+
#
194+
# Example:
195+
# 0: '1042MiB / 6951MiB'
196+
# 2: '1042.50MiB / 6951.00MiB'
197+
memory_precision="0"
198+
186199
187200
# Packages
188201
@@ -2787,10 +2800,18 @@ get_memory() {
27872800

27882801
[[ "$memory_percent" == "on" ]] && ((mem_perc=mem_used * 100 / mem_total))
27892802

2803+
# Format memory values with configurable precision
2804+
mem_precision=${memory_precision:-0}
2805+
27902806
case $memory_unit in
27912807
gib)
2792-
mem_used=$(awk '{printf "%.2f", $1 / $2}' <<< "$mem_used 1024")
2793-
mem_total=$(awk '{printf "%.2f", $1 / $2}' <<< "$mem_total 1024")
2808+
if ((mem_precision > 0)); then
2809+
mem_used=$(awk -v p="$mem_precision" '{printf "%." p "f", $1 / 1024}' <<< "$mem_used")
2810+
mem_total=$(awk -v p="$mem_precision" '{printf "%." p "f", $1 / 1024}' <<< "$mem_total")
2811+
else
2812+
mem_used=$(awk '{printf "%.0f", $1 / 1024}' <<< "$mem_used")
2813+
mem_total=$(awk '{printf "%.0f", $1 / 1024}' <<< "$mem_total")
2814+
fi
27942815
mem_label=GiB
27952816
;;
27962817

@@ -2799,9 +2820,18 @@ get_memory() {
27992820
mem_total=$((mem_total * 1024))
28002821
mem_label=KiB
28012822
;;
2823+
2824+
*)
2825+
# Default: MiB
2826+
if ((mem_precision > 0)); then
2827+
mem_used=$(awk -v p="$mem_precision" '{printf "%." p "f", $1}' <<< "$mem_used")
2828+
mem_total=$(awk -v p="$mem_precision" '{printf "%." p "f", $1}' <<< "$mem_total")
2829+
fi
2830+
mem_label=MiB
2831+
;;
28022832
esac
28032833

2804-
memory="${mem_used}${mem_label:-MiB} / ${mem_total}${mem_label:-MiB} ${mem_perc:+(${mem_perc}%)}"
2834+
memory="${mem_used}${mem_label} / ${mem_total}${mem_label} ${mem_perc:+(${mem_perc}%)}"
28052835

28062836
# Bars.
28072837
case $memory_display in
@@ -5052,6 +5082,7 @@ INFO:
50525082
--song_shorthand on/off Print the Artist/Album/Title on separate lines.
50535083
--memory_percent on/off Display memory percentage.
50545084
--memory_unit kib/mib/gib Memory output unit.
5085+
--memory_precision 0-3 Decimal places for memory values.
50555086
--music_player player-name Manually specify a player to use.
50565087
Available values are listed in the config file
50575088
@@ -5248,6 +5279,7 @@ get_args() {
52485279
"--music_player") music_player="$2" ;;
52495280
"--memory_percent") memory_percent="$2" ;;
52505281
"--memory_unit") memory_unit="$2" ;;
5282+
"--memory_precision") memory_precision="$2" ;;
52515283
"--cpu_temp")
52525284
cpu_temp="$2"
52535285
[[ "$cpu_temp" == "on" ]] && cpu_temp="C"

0 commit comments

Comments
 (0)