summaryrefslogtreecommitdiffstats
path: root/.scripts/statusbar/i3battery
blob: c13e6483fb2b06a9f6ef3c8caa0da12cea367aa8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh
# Give a battery name (e.g. BAT0) as an argument.

case $BLOCK_BUTTON in
    3) pgrep -x dunst >/dev/null && notify-send "<b>🔋 Battery module:</b>
🔋: discharging
♻: stagnant charge
🔌: charging
⚡: charged
- Text color reflects charge left" ;;
esac

capacity=$(cat /sys/class/power_supply/"$1"/capacity) || exit
status=$(cat /sys/class/power_supply/"$1"/status)

if [ "$capacity" -ge 80 ]; then
	color="#00FF00"
elif [ "$capacity" -ge 60 ]; then
	color="#FFFFFF"
elif [ "$capacity" -ge 40 ]; then
	color="#FFF600"
elif [ "$capacity" -ge 20 ]; then
	color="#FFAE00"
else
	color="#FF0000"
fi

[ "$status" = "Charging" ] && color="#FFF"

printf "<span color='%s'>%s %s</span>" "$color" "$(echo "$status" | sed -e "s/,//g;s/Discharging/🔋/;s/Charging/🔌/;s/Unknown/♻️/;s/Full/⚡/;s/ 0*/ /g;s/ :/ /g")" "$(echo "$capacity" | sed -e 's/$/%/')"