summaryrefslogtreecommitdiff
path: root/ratcpi
blob: 0ab7de5981a55b13719d9a837ac82d7835757933 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash

export PATH=~/bin:$PATH

#======================================================
# RatCPI version .10--Power management, Ratpoison style
# By Door
# edited by pks (average of battery capacities)
#======================================================

## Do you want to be informed of charging status?
##   This is distinct from "losing power" status.
## 0=no, 1=yes
informcharged=1

## How long to wait before in between checks.
## Default:  2 minutes (120 seconds)
delay=120

## Various important variables
plugged=$(eval acpi -V|grep off-line|wc -l)
charging=$(eval acpi -V|grep charging|wc -l)
never=$(eval acpi -V|grep never|wc -l)
battlevel=$(eval acpi)

if (($plugged==1))
then
eval 'ratpoison -c "echo $battlevel"'

elif (($charging==1))
then
eval 'ratpoison -c "echo $battlevel"'

else
echo $battlevel > /dev/null
fi

while winsys=$(ps -e | grep ratpoison | wc -l)
        [ "$winsys" != 0 ]
        do

        charge=$(eval acpi -V|grep charge|wc -l)
        never2=$(eval acpi -V|grep never|wc -l)

        lowbatt50=$(eval echo "$(acpi|cut -d" " -f4|sed "s|%||"|avg|round 0)%"|grep 50%|wc -l)
        lowbatt25=$(eval echo "$(acpi|cut -d" " -f4|sed "s|%||"|avg|round 0)%"|grep 25%|wc -l)
        lowbatt15=$(eval echo "$(acpi|cut -d" " -f4|sed "s|%||"|avg|round 0)%"|grep 15%|wc -l)
        lowbatt10=$(eval echo "$(acpi|cut -d" " -f4|sed "s|%||"|avg|round 0)%"|grep 10%|wc -l)
        lowbatt5=$(eval echo "$(acpi|cut -d" " -f4|sed "s|%||"|avg|round 0)%"|grep \ 5%|wc -l)
        lowbatt3=$(eval echo "$(acpi|cut -d" " -f4|sed "s|%||"|avg|round 0)%"|grep \ 3%|wc -l)
        lowbatt1=$(eval echo "$(acpi|cut -d" " -f4|sed "s|%||"|avg|round 0)%"|grep \ 1%|wc -l)

        hibat95=$(eval echo "$(acpi|cut -d" " -f4|sed "s|%||"|avg|round 0)%"|grep 95%|wc -l)
        hibat75=$(eval echo "$(acpi|cut -d" " -f4|sed "s|%||"|avg|round 0)%"|grep 75%|wc -l)

if (($charge==1))
   then

   if (($informcharged==0))
      then
      continue

   elif (($never2==1))
      then
	     echo $lowbatt50 > /dev/null

   elif (($hibat95==1))
	     then
	     eval 'ratpoison -c "echo Battery charged to 95%"'

   elif (($hibat75==1))
	     then
	     eval 'ratpoison -c "echo Battery charged to 75%"'

   elif (($lowbatt50==1))
	     then
	     eval 'ratpoison -c "echo Battery charged to 50%"'

   elif (($lowbatt25==1))
	     then
	     eval 'ratpoison -c "echo Battery charged to 25%"'

   elif (($lowbatt10==1))
	     then
	     eval 'ratpoison -c "echo Battery charged to 10%"'

   fi

fi

if (($charge==0))
   then

   if (($hibat95==1))
	     then
	     eval 'ratpoison -c "echo Battery at 95%"'

   elif (($hibat75==1))
	     then 
	     eval 'ratpoison -c "echo Battery at 75%"'

   elif (($lowbatt50==1))
	     then
	     eval 'ratpoison -c "echo Battery at 50%"'

   elif (($lowbatt25==1))
	     then 
	     eval 'ratpoison -c "echo Battery at 25%"'

   elif (($lowbatt15==1))
	     then
	     eval 'ratpoison -c "echo Battery at 15%"'

   elif (($lowbatt10==1))
	     then
	     eval 'ratpoison -c "echo Battery at 10%"'

   elif (($lowbatt5==1))
	     then
	     eval 'ratpoison -c "echo Battery at 5%!"'

   elif (($lowbatt3==1))
	     then
	     eval 'ratpoison -c "echo Battery at 3%!"'

   elif (($lowbatt1==1))
	     then
	     eval 'ratpoison -c "echo The battery is at 1%! Plug it in or turn it off!"'
   fi

fi

sleep $delay
done