diff options
| author | Robert Günzler <r@gnzler.io> | 2020-06-28 23:42:38 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2020-06-28 23:58:37 +0200 |
| commit | 386fd4322069fec73772b8db151ad75f7c1aa34b (patch) | |
| tree | 7661e2dbe3dc1394e2fa6796cd4d04654320aebe /.config/waybar/modules/toggl.lua | |
| parent | 03b5564359594f9526e090411531fb2d416fe516 (diff) | |
waybar: add redshift module
Diffstat (limited to '.config/waybar/modules/toggl.lua')
| -rwxr-xr-x | .config/waybar/modules/toggl.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/.config/waybar/modules/toggl.lua b/.config/waybar/modules/toggl.lua new file mode 100755 index 0000000..e44fce2 --- /dev/null +++ b/.config/waybar/modules/toggl.lua @@ -0,0 +1,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)) |