-
Notifications
You must be signed in to change notification settings - Fork 0
/
bat
executable file
·84 lines (73 loc) · 2.19 KB
/
bat
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
# shellcheck disable=1090,2154
# Give a battery name (e.g. BAT0) as an optional argument.
# TODO: Add support for multiple batteries.
[ "$1" ] && bat_dev=$1 || bat_dev="BAT0"
[ -d /sys/class/power_supply/$bat_dev ] || exit 1
case $BLOCK_BUTTON in
1) # Left Click
;;
2) # Middle Click
;;
3) # Right Click
;;
esac
# full battery
# almost full battery
# half full battery
# low battery
# no battery/dead
# capacity=$(echo scale=4\;$(cat /sys/class/power_supply/BAT0/charge_now)/$(cat /sys/class/power_supply/BAT0/charge_full)\*100 | bc | sed 's/0\{1,\}$//') || exit
# kernelcapacity=$(cat /sys/class/power_supply/$bat_dev/charge_now)
# kernelalarm=$(cat /sys/class/power_supply/$bat_dev/alarm)
. ~/.cache/wal/colors.sh
blockcolor=$color2
txtcolor=$color8
capacity=$(cat /sys/class/power_supply/$bat_dev/capacity)
if [ "$capacity" -ge 90 ]; then
color=$color7
icon=" "
elif [ "$capacity" -ge 60 ]; then
color="#ffffff"
icon=" "
elif [ "$capacity" -ge 40 ]; then
color="#ffff00"
icon=" "
elif [ "$capacity" -ge 10 ]; then
color="#ff0000"
icon=" "
else
color="#ff0000"
icon=" "
fi
[ "$(cat /sys/class/power_supply/$bat_dev/charge_now)" -ge \
"$(cat /sys/class/power_supply/$bat_dev/alarm)" ] &&
alarm="" || alarm="❗"
case "$(cat /sys/class/power_supply/$bat_dev/status)" in
Full)
statusicon="="
;;
Charging)
statusicon=\+
statuscolor="#00ff00"
;;
Discharging)
statusicon="-"
statuscolor="#ff0000"
;;
Unknown)
statusicon=\*
;;
'Not Charging')
statusicon=\!
;;
esac
# printf "<span color='%s'>%s</span><span color='%s'>%s</span>\n" "$color" "$alarm$capacity%" "$statuscolor" "$statusicon $icon"
printf "<b><span foreground='%s' background='%s'></span>" \
"$blockcolor" "$color0"
printf "<span foreground='%s' background='%s'> %s</span>" \
"$color" "$blockcolor" "${alarm}${icon}${capacity}%"
printf "<span foreground='%s' background='%s'>%s </span>" \
"$statuscolor" "$blockcolor" "${statusicon}"
printf "<span foreground='%s' background='%s'></span></b>\n" \
"$color0" "$blockcolor"