blob: 3aed4f9eb9d1754688b5d495e79b17bcca2bd300 (
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
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
|
{ pkgs, ... }:
let
name = "bat";
symbol = "·";
in
pkgs.writeScriptBin name
''
red="\e[31m"
grn="\e[32m"
ylw="\e[33m"
cyn="\e[36m"
blu="\e[34m"
prp="\e[35m"
bprp="\e[35;1m"
rst="\e[0m"
bat_status=""
bat_status=$( cat /sys/class/power_supply/BAT0/capacity )
if [ -z $bat_status ]; then
echo -ne "#[fg=color2]${symbol} #[fg=colour8]$HOSTNAME"
exit 0
fi
charging_status=$( cat /sys/class/power_supply/BAT0/status )
health() {
for i in {0..4}
do
if [[ $i -le $(( $bat_status/20 )) ]]; then
echo -ne "#[fg=colour1]${symbol} "
else
echo -ne "#[fg=colour8]${symbol} "
fi
done
echo
}
bat_status_small() {
if [[ "$charging_status" = *Charging* ]]; then
echo -ne "+$bat_status%"
else
echo -ne "$bat_status%"
fi
}
[ -z "$1" ] && {
bat_status_small
}
while getopts qi options
do
case $options in
i)
bat_status_small
;;
q)
if [[ "$charging_status" = *Charging* ]]; then
echo -ne "+ $(health)"
else
health
fi
esac
done
''
|