Enhanced --memory_unit functionality (own)

This commit is contained in:
Jin Asanami 2022-11-14 21:39:27 +09:00 committed by GitHub
parent c25ac3995b
commit 6462954f38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

151
neofetch
View file

@ -176,8 +176,9 @@ uptime_shorthand="on"
# off: '1801MiB / 7881MiB' # off: '1801MiB / 7881MiB'
memory_percent="off" memory_percent="off"
# Change memory output unit. # Change memory output unit & precision.
# #
# unit
# Default: 'mib' # Default: 'mib'
# Values: 'kib', 'mib', 'gib' # Values: 'kib', 'mib', 'gib'
# Flag: --memory_unit # Flag: --memory_unit
@ -186,8 +187,13 @@ memory_percent="off"
# kib '1020928KiB / 7117824KiB' # kib '1020928KiB / 7117824KiB'
# mib '1042MiB / 6951MiB' # mib '1042MiB / 6951MiB'
# gib: ' 0.98GiB / 6.79GiB' # gib: ' 0.98GiB / 6.79GiB'
#
# precision
# Default: '2'
# Values: integer ≥ 0
# Flag: --memory_precision
memory_unit="gib" memory_unit="gib"
mem_precision=2
# Packages # Packages
@ -3095,30 +3101,13 @@ get_memory() {
;; ;;
"Mac OS X" | "macOS" | "iPhone OS") "Mac OS X" | "macOS" | "iPhone OS")
if [[ $osx_version == 10.[4-5]* ]]; then hw_pagesize="$(sysctl -n hw.pagesize)"
mem_total="$(system_profiler SPHardwareDataType | grep Memory:)" mem_total="$(($(sysctl -n hw.memsize) / 1024 / 1024))"
mem_total="${mem_total/Memory\: /}" pages_app="$(($(sysctl -n vm.page_pageable_internal_count) - $(sysctl -n vm.page_purgeable_count)))"
mem_total="${mem_total/ MB/}" pages_wired="$(vm_stat | awk '/ wired/ { print $4 }')"
pages_compressed="$(vm_stat | awk '/ occupied/ { printf $5 }')"
mem_used="$(vm_stat | grep Pages\ active:)" pages_compressed="${pages_compressed:-0}"
mem_used="${mem_used/Pages active\: /}" mem_used="$(((pages_app + ${pages_wired//.} + ${pages_compressed//.}) * hw_pagesize / 1024 / 1024))"
mem_used="${mem_used/\./}"
pages_inactive=$(vm_stat | grep "Pages inactive")
pages_inactive=${pages_inactive/Pages inactive\: /}
pages_inactive=${pages_inactive/\./}
mem_used=$((mem_used + pages_inactive))
mem_used=$((mem_used * 4096 / 1048576))
else
hw_pagesize="$(sysctl -n hw.pagesize)"
mem_total="$(($(sysctl -n hw.memsize) / 1024 / 1024))"
pages_app="$(($(sysctl -n vm.page_pageable_internal_count) - $(sysctl -n vm.page_purgeable_count)))"
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))"
fi
;; ;;
"BSD" | "MINIX" | "ravynOS") "BSD" | "MINIX" | "ravynOS")
@ -3209,6 +3198,11 @@ get_memory() {
[[ "$memory_percent" == "on" ]] && ((mem_perc=mem_used * 100 / mem_total)) [[ "$memory_percent" == "on" ]] && ((mem_perc=mem_used * 100 / mem_total))
memory_unit_divider=1
memory_unit_multiplier=1
mu_mb="$mem_used"
mt_mb="$mem_total"
case $memory_unit in case $memory_unit in
gib) gib)
mem_used=$(awk '{printf "%.1f", $1 / $2}' <<< "$mem_used 1024") mem_used=$(awk '{printf "%.1f", $1 / $2}' <<< "$mem_used 1024")
@ -3223,13 +3217,25 @@ get_memory() {
;; ;;
esac esac
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}%)}" memory="${mem_used} ${mem_label:-MiB} / ${mem_total} ${mem_label:-MiB} ${mem_perc:+(${mem_perc}%)}"
# Bars. # Bars.
case $memory_display in case $memory_display in
"bar") memory="$(bar "${mem_used}" "${mem_total}")" ;; "bar") memory="$(bar "${mu_mb}" "${mt_mb}")" ;;
"infobar") memory="${memory} $(bar "${mem_used}" "${mem_total}")" ;; "infobar") memory="${memory} $(bar "${mu_mb}" "${mt_mb}")" ;;
"barinfo") memory="$(bar "${mem_used}" "${mem_total}")${info_color} ${memory}" ;; "barinfo") memory="$(bar "${mu_mb}" "${mt_mb}")${info_color} ${memory}" ;;
esac esac
} }
@ -5698,7 +5704,7 @@ INFO:
This can be used in bars and scripts like so: This can be used in bars and scripts like so:
memory=\"\$(neofetch memory)\"; memory=\"\${memory##*: }\" memory=\"\$(unifetch memory)\"; memory=\"\${memory##*: }\"
For multiple outputs at once (each line of info in an array): For multiple outputs at once (each line of info in an array):
@ -5788,7 +5794,9 @@ INFO:
--song_format format Print the song data in a specific format (see config file). --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. --song_shorthand on/off Print the Artist/Album/Title on separate lines.
--memory_percent on/off Display memory percentage. --memory_percent on/off Display memory percentage.
--memory_unit kib/mib/gib Memory output unit. --memory_unit kib/mib/gib/tib
Memory output unit.
--memory_precision integer Change memory output precision. (≥0, default=2)
--music_player player-name Manually specify a player to use. --music_player player-name Manually specify a player to use.
Available values are listed in the config file Available values are listed in the config file
@ -5856,56 +5864,42 @@ ASCII:
--ascii_colors x x x x x x Colors to print the ascii art --ascii_colors x x x x x x Colors to print the ascii art
--ascii_distro distro Which Distro's ascii art to print --ascii_distro distro Which Distro's ascii art to print
NOTE: AIX, AlmaLinux, Alpine, Alter, Amazon, AmogOS, Anarchy, NOTE: AIX, AlmaLinux, Alpine, Alter, Amazon, AmogOS, Anarchy, Android, Antergos, antiX, AOSC OS,
Android, Antergos, antiX, AOSC OS, AOSC OS/Retro, Aperio GNU/Linux, AOSC OS/Retro, Aperio GNU/Linux, Apricity, Arch, ArchBox, Archcraft, ARCHlabs, ArchMerge,
Apricity, Arch, ArchBox, Archcraft, ARCHlabs, ArchMerge, ArchStrike, ArchStrike, ArcoLinux, Artix, Arya, Asahi, AsteroidOS, astOS, Bedrock, BigLinux, Bitrig,
ArcoLinux, Artix, Arya, Asahi, AsteroidOS, astOS, Bedrock, BigLinux, BlackArch, blackPanther, BLAG, BlankOn, BlueLight, Bodhi, bonsai, BSD, BunsenLabs, Cachy OS,
Bitrig, BlackArch, blackPanther, BLAG, BlankOn, BlueLight, Bodhi, Calculate, CalinixOS, Carbs, CBL-Mariner, CelOS, Center, CentOS, Chakra, ChaletOS, Chapeau,
bonsai, BSD, BunsenLabs, Cachy OS, Calculate, CalinixOS, Carbs, CBL- ChonkySealOS, Chrom, Cleanjaro, Clear Linux OS, ClearOS, Clover, Cobalt Linux, Condres,
Mariner, CelOS, Center, CentOS, Chakra, ChaletOS, Chapeau, Container Linux by CoreOS, CRUX, Crystal Linux, Cucumber, CutefishOS, CyberOS, dahlia, DarkOs, Darwin,
ChonkySealOS, Chrom, Cleanjaro, Clear Linux OS, ClearOS, Clover, Debian, Deepin, DesaOS, Devuan, DracOS, DragonFly, Drauger, Elementary, Elive, EncryptOS, EndeavourOS,
Cobalt Linux, Condres, Container Linux by CoreOS, CRUX, Crystal Linux, Endless, Enso, EuroLinux, Exherbo, Exodia Predator OS, Fedora, Feren, Finnix, FreeBSD, FreeMiNT,
Cucumber, CutefishOS, CyberOS, dahlia, DarkOs, Darwin, Debian, Deepin, DesaOS, Frugalware, Funtoo, GalliumOS, Garuda, Gentoo, GhostBSD, glaucus, gNewSense, GNOME, GNU,
Devuan, DracOS, DragonFly, Drauger, Droidian, Elementary, Elive, EncryptOS, GoboLinux, GrapheneOS, Grombyang, Guix, Haiku, HarDClanZ, Hash, Huayra, HydroOS, Hyperbola,
EndeavourOS, Endless, Enso, EuroLinux, Exherbo, Exodia Predator OS, iglunix, instantOS, IRIX, Itc, januslinux, Kaisen, Kali, Kamuriki, KaOS, KDE, Kibojoe, Kogaion, Korora,
Fedora, Feren, Finnix, FreeBSD, FreeMiNT, Frugalware, Funtoo, KrassOS, KSLinux, Kubuntu, LangitKetujuh, LaxerOS, LEDE, LibreELEC, Linspire, Linux, Linux Lite,
GalliumOS, Garuda, Gentoo, GhostBSD, glaucus, gNewSense, GNOME, GNU, Linux Mint, Linux Mint Old, Live Raizo, LMDE, Lubuntu, Lunar, mac, Mageia, MagpieOS, Mandriva,
GoboLinux, GrapheneOS, Grombyang, Guix, Haiku, HarDClanZ, Hash, Manjaro, MassOS, MatuusOS, Maui, Mer, Minix, MIRACLE LINUX, MX, Namib, Neptune, NetBSD, Netrunner,
Huayra, HydroOS, Hyperbola, iglunix, instantOS, IRIX, Itc, Nitrux, NixOS, NNLinux, NomadBSD, Nurunner, NuTyX, Obarun, OBRevenge, Open Source Media Center,
januslinux, Kaisen, Kali, Kamuriki, KaOS, KDE, Kibojoe, Kogaion, Korora, OpenBSD, openEuler, OpenIndiana, openmamba, OpenMandriva, OpenStage, openSUSE, openSUSE Leap, openSUSE
KrassOS, KSLinux, Kubuntu, LangitKetujuh, LaxerOS, LEDE, LibreELEC, Tumbleweed, OpenWrt, OPNsense, Oracle, orchid, OS Elbrus, PacBSD, Parabola, parch, Pardus, Parrot,
Linspire, Linux, Linux Lite, Linux Mint, Linux Mint Old, Live Raizo, Parsix, PCBSD, PCLinuxOS, pearOS, Pengwin, Pentoo, Peppermint, Pisi, PNM Linux, Pop!_OS, Porteus,
LMDE, Lubuntu, Lunar, mac, Mageia, MagpieOS, Mandriva, Manjaro, PostMarketOS, Profelis SambaBOX, Proxmox, PuffOS, Puppy, PureOS, Q4OS, Qubes, Qubyt, Quibian,
MassOS, MatuusOS, Maui, Mer, Minix, MIRACLE LINUX, MX, Namib, Radix, Raspbian, ravynOS, Reborn OS, Red Star, Redcore, Redhat, Refracted Devuan, Regata,
Neptune, NetBSD, Netrunner, Nitrux, NixOS, NNLinux, NomadBSD, Nurunner, Regolith, rocky, Rosa, Sabayon, sabotage, Sailfish, SalentOS, Scientific, semc, Septor, Serene,
NuTyX, Obarun, OBRevenge, Open Source Media Center, OpenBSD, SharkLinux, ShastraOS, Siduction, SkiffOS, Slackware, SliTaz, SmartOS, Soda, Solus, Source Mage,
openEuler, OpenIndiana, openmamba, OpenMandriva, OpenStage, Sparky, Star, SteamOS, Sulin, SunOS, SwagArch, t2, Tails, TeArch, TorizonCore, Trisquel, Twister,
openSUSE, openSUSE Leap, openSUSE Tumbleweed, OpenWrt, OPNsense, Ubuntu, Ubuntu Budgie, Ubuntu Cinnamon, Ubuntu Kylin, Ubuntu MATE, Ubuntu Studio, Ubuntu Sway,
Oracle, orchid, OS Elbrus, PacBSD, Parabola, parch, Pardus, Parrot, Ubuntu Touch, Ubuntu-GNOME, ubuntu_old02, Ultramarine Linux, Univalent, Univention, Uos, uwuntu,
Parsix, PCBSD, PCLinuxOS, pearOS, Pengwin, Pentoo, Peppermint, Pisi, Vanilla, Venom, VNux, Void, VzLinux, wii-linux-ngx, Windows, Windows 10, Windows 11, XFerience, Xubuntu,
PNM Linux, Pop!_OS, Porteus, PostMarketOS, Profelis SambaBOX,
Proxmox, PuffOS, Puppy, PureOS, Q4OS, Qubes, Qubyt, Quibian, Radix,
Raspbian, ravynOS, Reborn OS, Red Star, Redcore, Redhat, Refracted
Devuan, Regata, Regolith, rocky, Rosa, Sabayon, sabotage, Sailfish,
SalentOS, Scientific, semc, Septor, Serene, SharkLinux, ShastraOS,
Siduction, SkiffOS, Slackware, SliTaz, SmartOS, Soda, Solus, Source
Mage, Sparky, Star, SteamOS, Sulin, SunOS, SwagArch, t2, Tails,
TeArch, TorizonCore, Trisquel, Twister, Ubuntu, Ubuntu Budgie,
Ubuntu Cinnamon, Ubuntu Kylin, Ubuntu MATE, Ubuntu Studio, Ubuntu
Sway, Ubuntu Touch, Ubuntu-GNOME, ubuntu_old02, Ultramarine Linux,
Univalent, Univention, Uos, uwuntu, Venom, VNux, Void, VzLinux, wii-
linux-ngx, Windows, Windows 10, Windows 11, XFerience, Xubuntu,
yiffOS, Zorin have ascii logos. yiffOS, Zorin have ascii logos.
NOTE: arch, dragonfly, Fedora, LangitKetujuh, nixos, redhat, Ubuntu NOTE: arch, dragonfly, Fedora, LangitKetujuh, nixos, redhat, Ubuntu have 'old' logo variants, use
have 'old' logo variants, use {distro}_old to use them. {distro}_old to use them.
NOTE: alpine, android, aoscosretro, arch, arcolinux, artix, NOTE: alpine, android, aoscosretro, arch, arcolinux, artix, CalinixOS, centos, cleanjaro, crux,
CalinixOS, centos, cleanjaro, crux, debian, dragonfly, elementary, debian, dragonfly, elementary, fedora, freebsd, garuda, gentoo, guix, haiku, hyperbola, linuxlite,
fedora, freebsd, garuda, gentoo, guix, haiku, hyperbola, linuxlite, linuxmint, mac, mageia, manjaro, mx, netbsd, nixos, openbsd, opensuse, orchid, parabola, popos,
linuxmint, mac, mageia, manjaro, mx, netbsd, nixos, openbsd, postmarketos, pureos, Raspbian, rocky, slackware, sunos, ubuntu, void have 'small' logo variants,
opensuse, orchid, parabola, popos, postmarketos, pureos, Raspbian,
rocky, slackware, sunos, ubuntu, void have 'small' logo variants,
use {distro}_small to use them. use {distro}_small to use them.
--ascii_bold on/off Whether or not to bold the ascii logo. --ascii_bold on/off Whether or not to bold the ascii logo.
@ -6004,6 +5998,7 @@ get_args() {
"--music_player") music_player="$2" ;; "--music_player") music_player="$2" ;;
"--memory_percent") memory_percent="$2" ;; "--memory_percent") memory_percent="$2" ;;
"--memory_unit") memory_unit="$2" ;; "--memory_unit") memory_unit="$2" ;;
"--memory_precision") mem_precision="$2" ;;
"--cpu_temp") "--cpu_temp")
cpu_temp="$2" cpu_temp="$2"
[[ "$cpu_temp" == "on" ]] && cpu_temp="C" [[ "$cpu_temp" == "on" ]] && cpu_temp="C"