blob: 7c9f0b91392ae22a8ae0a2d895bfd481f5377cfa (
plain) (
blame)
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
|
#!/usr/bin/env luajit
TOKEN = os.getenv("TOGGL_TOKEN")
if not TOKEN then
io.stderr:write("need TOGGL_TOKEN\n")
os.exit(1)
end
function timer_duration()
cmd = string.format('toggl -t %s -j timer ls | jq -r ".[0].duration"', TOKEN)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if not (s == '') then
return tonumber(s)
end
end
unix_time = os.time()
diff = timer_duration()
if not diff then
os.exit(0)
end
d = unix_time + diff
print(string.format('%dh %.2dm', d/(60*60), d/60%60))
|