-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdischarge.lua
executable file
·51 lines (45 loc) · 1.36 KB
/
discharge.lua
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/env lua
local h_ok, h = pcall(require, "helpers")
if not h_ok then
return
end
local target = 15
local function charge_notice()
os.execute('notify-send -u normal "Charging"')
return nil
end
while true do
local t = {}
local battery = io.popen('acpi', 'r')
if not battery then
h.check(1, "Could not run the acpi command")
else
local output = battery:read("*all")
local discharge = output:match( "Discharging, (%d+)" )
local charge = output:match( "Charging, (%d+)" )
local full = output:match( "Full" )
discharge = tonumber(discharge)
charge = tonumber(charge)
if discharge then
table.insert(t, discharge)
end
if full then
os.exit(0, true)
end
if charge then
while charge == charge do
charge_notice()
h.dunst_close()
os.execute('loop ~/programming/lua_projects/charge.lua')
os.exit(0, true)
end
end
battery:close()
if discharge == nil then
-- h.check(1, "Could not populate table with Discharge value ")
elseif discharge < target then
h.check(1, "Charge Me!!")
end
return t
end
end