aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/.scripts/i3barbattery
blob: edc89c36cdd730d68c864a69dc88cfe6b23c32c9 (plain)
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
31
32
33
34
#!/bin/sh
# Taken from Luke Smith's rice
# Takes battery name as an argument (e.g. BAT0)

case $BLOCK_BUTTON in
    3) notify-send "🔋 Battery module" "🔋: discharging
🛑: not charging
♻: stagnant charge
🔌: charging
⚡: charged
❗: battery very low!
- 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 75 ]; then
	color="#689d6a"
elif [ "$capacity" -ge 50 ]; then
	color="#ffffff"
elif [ "$capacity" -ge 25 ]; then
	color="#ffff00"
else
	color="#ff0000"
	warn="❗"
fi

[ -z $warn ] && warn=" "

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

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