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'
memory_percent="off"
# Change memory output unit.
# Change memory output unit & precision.
#
# unit
# Default: 'mib'
# Values: 'kib', 'mib', 'gib'
# Flag: --memory_unit
@ -186,8 +187,13 @@ memory_percent="off"
# kib '1020928KiB / 7117824KiB'
# mib '1042MiB / 6951MiB'
# gib: ' 0.98GiB / 6.79GiB'
#
# precision
# Default: '2'
# Values: integer ≥ 0
# Flag: --memory_precision
memory_unit="gib"
mem_precision=2
# Packages
@ -3095,30 +3101,13 @@ get_memory() {
;;
"Mac OS X" | "macOS" | "iPhone OS")
if [[ $osx_version == 10.[4-5]* ]]; then
mem_total="$(system_profiler SPHardwareDataType | grep Memory:)"
mem_total="${mem_total/Memory\: /}"
mem_total="${mem_total/ MB/}"
mem_used="$(vm_stat | grep Pages\ active:)"
mem_used="${mem_used/Pages active\: /}"
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
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))"
;;
"BSD" | "MINIX" | "ravynOS")
@ -3209,6 +3198,11 @@ get_memory() {
[[ "$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
gib)
mem_used=$(awk '{printf "%.1f", $1 / $2}' <<< "$mem_used 1024")
@ -3223,13 +3217,25 @@ get_memory() {
;;
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}%)}"
# 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
}
@ -5698,7 +5704,7 @@ INFO:
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):
@ -5788,7 +5794,9 @@ 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 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.
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_distro distro Which Distro's ascii art to print
NOTE: AIX, AlmaLinux, Alpine, Alter, Amazon, AmogOS, Anarchy,
Android, Antergos, antiX, AOSC OS, AOSC OS/Retro, Aperio GNU/Linux,
Apricity, Arch, ArchBox, Archcraft, ARCHlabs, ArchMerge, ArchStrike,
ArcoLinux, Artix, Arya, Asahi, AsteroidOS, astOS, Bedrock, BigLinux,
Bitrig, BlackArch, blackPanther, BLAG, BlankOn, BlueLight, Bodhi,
bonsai, BSD, BunsenLabs, Cachy OS, Calculate, CalinixOS, Carbs, CBL-
Mariner, CelOS, Center, CentOS, Chakra, ChaletOS, Chapeau,
ChonkySealOS, Chrom, Cleanjaro, Clear Linux OS, ClearOS, Clover,
Cobalt Linux, Condres, Container Linux by CoreOS, CRUX, Crystal Linux,
Cucumber, CutefishOS, CyberOS, dahlia, DarkOs, Darwin, Debian, Deepin, DesaOS,
Devuan, DracOS, DragonFly, Drauger, Droidian, Elementary, Elive, EncryptOS,
EndeavourOS, Endless, Enso, EuroLinux, Exherbo, Exodia Predator OS,
Fedora, Feren, Finnix, FreeBSD, FreeMiNT, Frugalware, Funtoo,
GalliumOS, Garuda, Gentoo, GhostBSD, glaucus, gNewSense, GNOME, GNU,
GoboLinux, GrapheneOS, Grombyang, Guix, Haiku, HarDClanZ, Hash,
Huayra, HydroOS, Hyperbola, iglunix, instantOS, IRIX, Itc,
januslinux, Kaisen, Kali, Kamuriki, KaOS, KDE, Kibojoe, Kogaion, Korora,
KrassOS, KSLinux, Kubuntu, LangitKetujuh, LaxerOS, LEDE, LibreELEC,
Linspire, Linux, Linux Lite, Linux Mint, Linux Mint Old, Live Raizo,
LMDE, Lubuntu, Lunar, mac, Mageia, MagpieOS, Mandriva, Manjaro,
MassOS, MatuusOS, Maui, Mer, Minix, MIRACLE LINUX, MX, Namib,
Neptune, NetBSD, Netrunner, Nitrux, NixOS, NNLinux, NomadBSD, Nurunner,
NuTyX, Obarun, OBRevenge, Open Source Media Center, OpenBSD,
openEuler, OpenIndiana, openmamba, OpenMandriva, OpenStage,
openSUSE, openSUSE Leap, openSUSE Tumbleweed, OpenWrt, OPNsense,
Oracle, orchid, OS Elbrus, PacBSD, Parabola, parch, Pardus, Parrot,
Parsix, PCBSD, PCLinuxOS, pearOS, Pengwin, Pentoo, Peppermint, Pisi,
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,
NOTE: AIX, AlmaLinux, Alpine, Alter, Amazon, AmogOS, Anarchy, Android, Antergos, antiX, AOSC OS,
AOSC OS/Retro, Aperio GNU/Linux, Apricity, Arch, ArchBox, Archcraft, ARCHlabs, ArchMerge,
ArchStrike, ArcoLinux, Artix, Arya, Asahi, AsteroidOS, astOS, Bedrock, BigLinux, Bitrig,
BlackArch, blackPanther, BLAG, BlankOn, BlueLight, Bodhi, bonsai, BSD, BunsenLabs, Cachy OS,
Calculate, CalinixOS, Carbs, CBL-Mariner, CelOS, Center, CentOS, Chakra, ChaletOS, Chapeau,
ChonkySealOS, Chrom, Cleanjaro, Clear Linux OS, ClearOS, Clover, Cobalt Linux, Condres,
Container Linux by CoreOS, CRUX, Crystal Linux, Cucumber, CutefishOS, CyberOS, dahlia, DarkOs, Darwin,
Debian, Deepin, DesaOS, Devuan, DracOS, DragonFly, Drauger, Elementary, Elive, EncryptOS, EndeavourOS,
Endless, Enso, EuroLinux, Exherbo, Exodia Predator OS, Fedora, Feren, Finnix, FreeBSD, FreeMiNT,
Frugalware, Funtoo, GalliumOS, Garuda, Gentoo, GhostBSD, glaucus, gNewSense, GNOME, GNU,
GoboLinux, GrapheneOS, Grombyang, Guix, Haiku, HarDClanZ, Hash, Huayra, HydroOS, Hyperbola,
iglunix, instantOS, IRIX, Itc, januslinux, Kaisen, Kali, Kamuriki, KaOS, KDE, Kibojoe, Kogaion, Korora,
KrassOS, KSLinux, Kubuntu, LangitKetujuh, LaxerOS, LEDE, LibreELEC, Linspire, Linux, Linux Lite,
Linux Mint, Linux Mint Old, Live Raizo, LMDE, Lubuntu, Lunar, mac, Mageia, MagpieOS, Mandriva,
Manjaro, MassOS, MatuusOS, Maui, Mer, Minix, MIRACLE LINUX, MX, Namib, Neptune, NetBSD, Netrunner,
Nitrux, NixOS, NNLinux, NomadBSD, Nurunner, NuTyX, Obarun, OBRevenge, Open Source Media Center,
OpenBSD, openEuler, OpenIndiana, openmamba, OpenMandriva, OpenStage, openSUSE, openSUSE Leap, openSUSE
Tumbleweed, OpenWrt, OPNsense, Oracle, orchid, OS Elbrus, PacBSD, Parabola, parch, Pardus, Parrot,
Parsix, PCBSD, PCLinuxOS, pearOS, Pengwin, Pentoo, Peppermint, Pisi, 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,
Vanilla, Venom, VNux, Void, VzLinux, wii-linux-ngx, Windows, Windows 10, Windows 11, XFerience, Xubuntu,
yiffOS, Zorin have ascii logos.
NOTE: arch, dragonfly, Fedora, LangitKetujuh, nixos, redhat, Ubuntu
have 'old' logo variants, use {distro}_old to use them.
NOTE: arch, dragonfly, Fedora, LangitKetujuh, nixos, redhat, Ubuntu have 'old' logo variants, use
{distro}_old to use them.
NOTE: alpine, android, aoscosretro, arch, arcolinux, artix,
CalinixOS, centos, cleanjaro, crux, debian, dragonfly, elementary,
fedora, freebsd, garuda, gentoo, guix, haiku, hyperbola, linuxlite,
linuxmint, mac, mageia, manjaro, mx, netbsd, nixos, openbsd,
opensuse, orchid, parabola, popos, postmarketos, pureos, Raspbian,
rocky, slackware, sunos, ubuntu, void have 'small' logo variants,
NOTE: alpine, android, aoscosretro, arch, arcolinux, artix, CalinixOS, centos, cleanjaro, crux,
debian, dragonfly, elementary, fedora, freebsd, garuda, gentoo, guix, haiku, hyperbola, linuxlite,
linuxmint, mac, mageia, manjaro, mx, netbsd, nixos, openbsd, opensuse, orchid, parabola, popos,
postmarketos, pureos, Raspbian, rocky, slackware, sunos, ubuntu, void have 'small' logo variants,
use {distro}_small to use them.
--ascii_bold on/off Whether or not to bold the ascii logo.
@ -6004,6 +5998,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"