-
Notifications
You must be signed in to change notification settings - Fork 0
/
batt.sh
executable file
·48 lines (38 loc) · 1.08 KB
/
batt.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
#!/usr/bin/env bash
################################
# Shows info about connected batteries.
#
# Dependencies:
# - acpi
#
# @return {Number(%)}: Current battery charge
################################
dir=$(dirname $0)
source $dir/util.sh
full=""
short=""
stat=0
# Exit if no battery was found
if [[ "$(acpi)" == "" ]]; then exit 0; fi
state=$(acpi | sed -n 's/Battery [0]: \([A-Z]\).*, .*/\1/p')
#state1=$(acpi | sed -n 's/Battery [1]: \([A-Z]\).*, .*/\1/p')
chg=$(acpi | sed -n 's/Battery [0]:.*, \([0-9]\{1,3\}\)%.*/\1/p')
#chg2=$(acpi | sed -n 's/Battery [1]:.*, \([0-9]\{1,3\}\)%.*/\1/p')
# Charging or Unknown
if [[ $state == "C" ]] || [[ $state == "U" ]] && [[ $state1 == "C" ]] || [[ $state1 == "U" ]];then
icon=""
fi
if [[ $state != "C" ]] && [[ $state1 != "C" ]];then
icon=""
fi
if [[ $chg -le 10 ]] && [[ $chg2 -le 10 ]];then
icon=""
stat=33
LEVEL="critical"
/usr/bin/notify-send --expire-time=0 --urgency=$LEVEL "Battery critical,please connect to power socket" "Exit Code: $LEVEL"
fi
full="$icon $chg% "
short="$chg% %"
echo $full
echo $short
exit $stat