-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_battery.sh
executable file
·50 lines (45 loc) · 1.25 KB
/
get_battery.sh
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
#!/bin/bash
#
# A script that outputs battery percentage after "BAT: "
# It outputs colors, using pango markup
# battery information is stored in this directory
bat_dir="/sys/class/power_supply/BAT1"
percentage=$(cat ${bat_dir}/capacity) # current percentage
# is the battery charging?
state=$(cat ${bat_dir}/status)
# choosing color for percentage
if [ ${percentage} -le 20 ]
then
if [ "${state}" == "Discharging" ]
then
# show only when last showed 5 minutes ago
alreadyshowed=$(find "$(dirname "$0")" -name "$(basename "$0")" -cmin -5 | wc -l)
if [ ${alreadyshowed} -eq 0 ]
then
# mpv --no-terminal --fs --loop=6 /home/klaasg/memes/batterylow.mp4 &
i3-msg fullscreen disable >/dev/null
mpv --no-terminal --loop=6 /home/klaasg/memes/batterylow.mp4 &
touch "$0"
fi
fi
pcolor="#FF1D8E"
elif [ ${percentage} -ge 80 ]
then
pcolor="green"
if [ ${percentage} -eq 100 ]
then
pcolor="yellow"
fi
else
pcolor="white"
fi
# choosing color for BAT sign
if [ "${state}" == "Discharging" ]
then
color="white"
else
color="yellow"
fi
# echo correct output
echo -e "<span color='${color}'>BAT:</span> <span color='${pcolor}'>${percentage}%</span>"
exit 0