Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions neofetch
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ memory_percent="off"
# Change memory output unit.
#
# Default: 'mib'
# Values: 'kib', 'mib', 'gib'
# Values: 'kib', 'mib', 'gib', 'tib'
# Flag: --memory_unit
#
# Example:
Expand All @@ -181,6 +181,12 @@ memory_percent="off"
# gib: ' 0.98GiB / 6.79GiB'
memory_unit="mib"

# Change memory output precision.
#
# Default: '2'
# Values: integer ≥ 0
# Flag: --memory_precision
mem_precision=2

# Packages

Expand Down Expand Up @@ -2710,7 +2716,7 @@ get_memory() {
pages_wired="$(vm_stat | awk '/ wired/ { print $4 }')"
pages_compressed="$(vm_stat | awk '/ occupied/ { printf $5 }')"
pages_compressed="${pages_compressed:-0}"
mem_used="$(((${pages_app} + ${pages_wired//.} + ${pages_compressed//.}) * hw_pagesize / 1024 / 1024))"
mem_used="$(((pages_app + ${pages_wired//.} + ${pages_compressed//.}) * hw_pagesize / 1024 / 1024))"
;;

"BSD" | "MINIX")
Expand Down Expand Up @@ -2801,27 +2807,51 @@ get_memory() {

[[ "$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

# Keep a copy of the original megabyte values because progress bar need them
mu_mb="$mem_used"
mt_mb="$mem_total"

case $memory_unit in
tib)
mem_label=TiB
memory_unit_divider=$((1024 * 1024))
;;

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
;;

kib)
mem_used=$((mem_used * 1024))
mem_total=$((mem_total * 1024))
mem_label=KiB
memory_unit_multiplier=1024
;;
esac

# Uses temp variables from above: memory_unit_divider, memory_unit_multiplier
if test "$memory_unit_divider" -ge 1; then
printf -v mem_used "%'.*f" \
"${mem_precision}" \
$((mem_used / memory_unit_divider)).$((mem_used % memory_unit_divider))
printf -v mem_total "%'.*f" \
"${mem_precision}" \
$((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))
mem_total=$((mem_total * memory_unit_multiplier))
fi

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

# Bars.
case $memory_display in
"bar") memory="$(bar "${mem_used}" "${mem_total}")" ;;
"infobar") memory="${memory} $(bar "${mem_used}" "${mem_total}")" ;;
"barinfo") memory="$(bar "${mem_used}" "${mem_total}")${info_color} ${memory}" ;;
"bar") memory="$(bar "${mu_mb}" "${mt_mb}")" ;;
"infobar") memory="${memory} $(bar "${mu_mb}" "${mt_mb}")" ;;
"barinfo") memory="$(bar "${mu_mb}" "${mt_mb}")${info_color} ${memory}" ;;
esac
}

Expand Down Expand Up @@ -5071,7 +5101,8 @@ INFO:
--song_format format Print the song data in a specific format (see config file).
--song_shorthand on/off Print the Artist/Album/Title on separate lines.
--memory_percent on/off Display memory percentage.
--memory_unit kib/mib/gib Memory output unit.
--memory_unit (k/m/g/t)ib Memory output unit.
--memory_precision integer Change memory output precision. (≥0, default=2)
--music_player player-name Manually specify a player to use.
Available values are listed in the config file

Expand Down Expand Up @@ -5281,6 +5312,7 @@ get_args() {
"--music_player") music_player="$2" ;;
"--memory_percent") memory_percent="$2" ;;
"--memory_unit") memory_unit="$2" ;;
"--memory_precision") mem_precision="$2" ;;
"--cpu_temp")
cpu_temp="$2"
[[ "$cpu_temp" == "on" ]] && cpu_temp="C"
Expand Down