52 lines
1.4 KiB
Bash
Executable file
52 lines
1.4 KiB
Bash
Executable file
#!/bin/sh
|
|
# Battery indicator for dwmblocks
|
|
|
|
# Total battery charge
|
|
total=0
|
|
batteries=0
|
|
for battery in /sys/class/power_supply/BAT?* ; do
|
|
capacity=$(cat $battery/capacity 2>/dev/null || break)
|
|
total=$((capacity+total))
|
|
batteries=$(($batteries+1))
|
|
done
|
|
|
|
# If there's a total, get average, if else, print a plug
|
|
[ $total -gt 0 ] && bat=$(($total/$batteries)) || bat=""
|
|
[ "$bat" = "" ] && echo "$bat" && exit
|
|
|
|
# If something is charging, change status
|
|
grep -rq 'Charging' /sys/class/power_supply/BAT* 2>/dev/null && stat='Charging'
|
|
|
|
# Get graphical battery level
|
|
case 1 in
|
|
$((bat >= 98)) ) icon="" ;;
|
|
$((bat >= 90)) ) icon="" ;;
|
|
$((bat >= 80)) ) icon="" ;;
|
|
$((bat >= 70)) ) icon="" ;;
|
|
$((bat >= 60)) ) icon="" ;;
|
|
$((bat >= 50)) ) icon="" ;;
|
|
$((bat >= 40)) ) icon="" ;;
|
|
$((bat >= 30)) ) icon="" ;;
|
|
$((bat >= 20)) ) icon="" ;;
|
|
$((bat >= 10)) ) icon="" ;;
|
|
$((bat >= 0)) ) icon="" ;;
|
|
esac
|
|
|
|
# Charging indicator if status file indicates such state
|
|
if [ "$stat" = "Charging" ] ; then
|
|
icon="$(printf '%s' "$icon" | sed '
|
|
s///;
|
|
s///;
|
|
s///;
|
|
s///;
|
|
s///;
|
|
s///;
|
|
s///;
|
|
s///;
|
|
s///;
|
|
s///;
|
|
s///;
|
|
')"
|
|
fi
|
|
|
|
echo "$icon"
|