-
Notifications
You must be signed in to change notification settings - Fork 4
/
dzen-batt-mon
executable file
·78 lines (66 loc) · 2.4 KB
/
dzen-batt-mon
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
#!/bin/sh
#
# by lyon8 (lyon8@gmx.net)
# show your laptop battery state in dzen
BG='#000' # dzen backgrounad
FG='#ddd' # dzen foreground
W=265 # width of the dzen bar
GW=50 # width of the gauge
GFG='#999' # color of the gauge
GH=12 # height of the gauge
GBG='#333' # color of gauge background
X=1547 # x position
Y=0 # y position
FN='"xft:Liberation Mono:size=7"' # font
STATEFILE='/proc/acpi/battery/BAT0/state' # battery's state file
INFOFILE='/proc/acpi/battery/BAT0/info' # battery's info file
MIDBAT=65 # percentage of battery life marked as low
MIDCOL='#dddd47' # color when battery is low
LOWBAT=30 # percentage of battery life marked as low
LOWCOL='#dd4747' # color when battery is low
TIME_INT=15 # time interval in seconds
# Path to the icons for dzen
ICON_PATH="$HOME/.data/icons/dzen"
# Today's date & current time
DATE_FORMAT="%d %b %Y %H.%M"
gdbar="$([ -x /opt/dzen/bin/gdbar ] && echo '/opt/dzen/bin/gdbar' || echo 'gdbar')"
# whether or not to do a notification
doNotify=0
notify() {
notify-send --urgency=$1 --icon=$2 "Battery" "$3"
}
while true; do
# look up battery's data
BAT_FULL=`cat $INFOFILE|grep design|line|cut -d " " -f 11`;
STATUS=`acpi -a | cut -d':' -f2`;
RCAP=`cat $STATEFILE|grep remaining|cut -d " " -f 8`;
# calculate remaining power
RPERCT=`expr $RCAP \* 100`;
RPERC=`expr $RPERCT / $BAT_FULL`;
# draw the bar and pipe everything into dzen
if [ $RPERC -gt $MIDBAT ]; then GFGC=$GFG; fi
if [ $RPERC -le $MIDBAT ]; then GFGC=$MIDCOL; fi
if [ $RPERC -le $LOWBAT ]; then GFGC=$LOWCOL; fi
case $RPERC in
$LOWBAT)
message="Battery getting low, better plug in..."
level="normal"
icon="/usr/share/icons/gnome/32x32/status/battery-low.png"
notify $level $icon "$message"
;;
15)
message="Battery dangerously low! Plug in AC!"
level="critical"
icon="/usr/share/icons/gnome/32x32/status/battery-caution.png"
notify $level $icon "$message"
;;
esac
echo -n $(date +"$DATE_FORMAT")
if [ "$STATUS" = " on-line" ] ; then
echo -n " ^i(${ICON_PATH}/ac_01.xbm)"
else
echo -n " ^i(${ICON_PATH}/battery.xbm)"
fi
eval echo $RPERC | $gdbar -h $GH -w $GW -fg $GFGC -bg $GBG
sleep $TIME_INT;
done | dzen2 -ta c -tw $W -y $Y -x $X -fg "$FG" -bg "$BG" -fn "$FN" -h 18