47 lines
1.8 KiB
Bash
Executable file
47 lines
1.8 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)) ) bar="━━━━━━━━━━" ;;
|
|
$((bat >= 90)) ) bar="━━━━━━━━━─" ;;
|
|
$((bat >= 80)) ) bar="━━━━━━━━──" ;;
|
|
$((bat >= 70)) ) bar="━━━━━━━───" ;;
|
|
$((bat >= 60)) ) bar="━━━━━━────" ;;
|
|
$((bat >= 50)) ) bar="━━━━━─────" ;;
|
|
$((bat >= 40)) ) bar="━━━━──────" ;;
|
|
$((bat >= 30)) ) bar="━━━───────" ;;
|
|
$((bat >= 20)) ) bar="━━────────" ;;
|
|
$((bat >= 10)) ) bar="━!────────" ;;
|
|
$((bat >= 0)) ) bar="CHARGE NOW" ;;
|
|
esac
|
|
|
|
# Charging indicator if status file indicates such state
|
|
[ "$stat" != "Charging" ] && icon="" || icon=""
|
|
echo "$icon $bar"
|
|
|
|
# Warning when battery is under 10% capacity and not charging
|
|
[ $((bat)) -lt 16 ] && [ $((bat)) -gt 14 ] && [ "$stat" != "Charging" ] &&
|
|
notify-send --replace-id=15 " Battery" "Capacity at $bat%"
|
|
|
|
[ $((bat)) -lt 11 ] && [ $((bat)) -gt 9 ] && [ "$stat" != "Charging" ] &&
|
|
notify-send --replace-id=15 " Battery" "Capacity at $bat%"
|
|
|
|
[ $((bat)) -lt 6 ] && [ "$stat" != "Charging" ] &&
|
|
notify-send --replace-id=15 " Battery" "Capacity at $bat%"
|