Add battery support for Linux system-info script

This commit is contained in:
Kenneth Benzie 2023-06-01 21:52:27 +01:00
parent d852c46bc8
commit 31187c6d63
2 changed files with 23 additions and 4 deletions

View File

@ -22,17 +22,36 @@ else
} }
fi fi
if [ "`acpi -b`" != "No support for device type: power_supply" ]; then
function get_battery {
acpi -b | \
awk '{ print $4 }' | \
awk '$battery ~ /.*/ {
printf "%3d%% %s\n", $battery, substr("󰁹󰂂󰂁󰂀󰁿󰁾󰁽󰁼󰁻󰁺󰂎", int($battery / 9), 1)
}'
}
else
function get_battery {
echo ''
}
fi
# Cleanup cache file when interrupted. # Cleanup cache file when interrupted.
trap '[ -f $cache_file ] && rm $cache_file; exit' INT trap '[ -f $cache_file ] && rm $cache_file; exit' INT
trap '[ -f $cache_file ] && rm $cache_file; exit' TERM trap '[ -f $cache_file ] && rm $cache_file; exit' TERM
while true; do while true; do
# Parse the current CPU load on all cores/threads. # Parse the current CPU load on all cores/threads.
cpu_load=`mpstat -P ALL -n 1 -u 1 -o JSON | \ cpu_load=" `mpstat -P ALL -n 1 -u 1 -o JSON | \
jq '.sysstat.hosts[0].statistics[0]["cpu-load"][1:]|.[].idle' | \ jq '.sysstat.hosts[0].statistics[0]["cpu-load"][1:]|.[].idle' | \
awk '$idle ~ /[-.0-9]*/ { printf "%s", substr("█▇▆▅▄▃▂▁ ", int($idle / 11), 1) }'` awk '$idle ~ /[-.0-9]*/ { printf "%s", substr("█▇▆▅▄▃▂▁ ", int($idle / 11), 1) }'`"
# Parse the current CPU package temperature. # Parse the current CPU package temperature.
cpu_temp=$(get_cpu_temp) cpu_temp=$(get_cpu_temp)
# Get the battery status if present.
battery=$(get_battery)
# Write to the cache file. # Write to the cache file.
echo "$cpu_temp $cpu_load" > $cache_file echo "$cpu_temp$cpu_load$battery" > $cache_file
done done

View File

@ -138,7 +138,7 @@ setw -g status-style fg=colour240,bg=colour233
setw -g status-right "#[fg=colour240]#(cat ~/.cache/tmux/system-info)#[fg=white] %a %d-%m-%y %H:%M " setw -g status-right "#[fg=colour240]#(cat ~/.cache/tmux/system-info)#[fg=white] %a %d-%m-%y %H:%M "
setw -g status-right-style fg=white,bg=colour233 setw -g status-right-style fg=white,bg=colour233
if -b '[ "`uname`" != "Darwin" ]' \ if -b '[ "`uname`" != "Darwin" ]' \
'run "tmux setw -g status-right-length $((`nproc --all` + 32))"' 'run "tmux setw -g status-right-length $((`nproc --all` + 48))"'
# Active window status style # Active window status style
setw -g window-status-current-format " #{window_index}: #{window_name}" setw -g window-status-current-format " #{window_index}: #{window_name}"