system-info: Enable CPU load and battery icon on macOS

This commit is contained in:
Kenneth Benzie 2023-01-06 21:44:05 +00:00
parent f4aed11002
commit 235bf058e5
2 changed files with 24 additions and 10 deletions

View File

@ -36,9 +36,9 @@ while true; do
"(Get-WmiObject win32_battery).EstimatedChargeRemaining" \ "(Get-WmiObject win32_battery).EstimatedChargeRemaining" \
| sed 's/\r//') | sed 's/\r//')
if [ "" != "$raw_battery" ]; then if [ "" != "$raw_battery" ]; then
battery="$(printf "%3d%%" "$raw_battery") $(echo $raw_battery | \ battery="$(echo $raw_battery | awk '$battery ~ /.*/ {
awk '$raw_battery ~ /.*/ { printf "%s\n", \ printf "%3d%% %s\n", $battery, substr("", int($battery / 9), 1)
substr("", int($raw_battery / 9), 1) }')" }')"
fi fi
echo "$cpu_temp$cpu_load$battery" > $cache_file echo "$cpu_temp$cpu_load$battery" > $cache_file

View File

@ -17,13 +17,27 @@ ioreg -w0 -l | grep BatteryInstalled &> /dev/null && \
has_battery=true || has_battery=false has_battery=true || has_battery=false
while true; do while true; do
# Get the current CPU temperature. # # Get the current CPU temperature.
cpu_temp="`/usr/local/bin/osx-cpu-temp`" # cpu_temp="`/usr/local/bin/osx-cpu-temp`"
cpu_load=$(sudo powermetrics --format text \
--sample-rate 1200 --sample-count 1 --samplers cpu_power |
grep --color=never -E 'CPU \d idle residency:' |
grep --color=never -Eo '\d+\.\d+' |
gawk '$idle ~ /[-.0-9]*/ { printf "%s", substr("█▇▆▅▄▃▂▁ ", int($idle / 10), 1) }'
)
# Parse the current battery charge percentage. # Parse the current battery charge percentage.
$has_battery && \ if $has_battery; then
battery=" `pmset -g batt | grep --color=never -Eo '\d+%'` ↯" raw_battery="$(pmset -g batt | \
grep --color=never 'InternalBattery' | \
grep --color=never -Eo '\d+%' | \
grep --color=never -Eo '\d+')"
battery="$(echo $raw_battery | gawk '$battery ~ /.*/ {
printf "%3d%% %s\n", $battery, substr("", int($battery / 9), 1)
}')"
fi
# Write to the cache file. # Write to the cache file.
echo "$cpu_temp$battery" > $cache_file echo "$cpu_temp$cpu_load$battery" > $cache_file
# Don't spin, sleep instead.
sleep 2
done done