Compare commits
No commits in common. "d367d166a91baeb127bf4b74d2169ae39fc974af" and "fa3b27f66140a558803e19c7ce1f1f7a79eddf7a" have entirely different histories.
d367d166a9
...
fa3b27f661
@ -1,3 +0,0 @@
|
|||||||
## dates and their corresponding seconds been here :)
|
|
||||||
[24-10-07]
|
|
||||||
u80864958_at_u80864958 = 432
|
|
@ -1,7 +0,0 @@
|
|||||||
# Timer
|
|
||||||
|
|
||||||
Timer times the time it took you to realize your project
|
|
||||||
|
|
||||||
Counts the time in your editor inside on directory.
|
|
||||||
Not beeing inside the editor for less than 5 minutes gets counted as beeing
|
|
||||||
inside the editor.
|
|
107
lua/timer.lua
107
lua/timer.lua
@ -1,15 +1,12 @@
|
|||||||
local TOML = require("toml")
|
local TOML = require("toml")
|
||||||
function trim(s)
|
|
||||||
return (s:gsub("^%s*(.-)%s*$", "%1"))
|
|
||||||
end
|
|
||||||
|
|
||||||
local augroup = vim.api.nvim_create_augroup("Timer", { clear = true })
|
local augroup = vim.api.nvim_create_augroup("Timer", { clear = true })
|
||||||
local filename = ".timer.toml"
|
|
||||||
local username = trim(os.getenv("USER")) .. "_at_" .. trim(io.popen("hostname -s"):read("*a"))
|
|
||||||
local focus_events = {}
|
local focus_events = {}
|
||||||
local clean_to = 1
|
local clean_to = 1
|
||||||
|
|
||||||
|
function trim(s)
|
||||||
|
return (s:gsub("^%s*(.-)%s*$", "%1"))
|
||||||
|
end
|
||||||
|
|
||||||
local function clean_from(from, events)
|
local function clean_from(from, events)
|
||||||
local to = 1
|
local to = 1
|
||||||
@ -48,7 +45,7 @@ local function clean_from(from, events)
|
|||||||
return clean_events
|
return clean_events
|
||||||
end
|
end
|
||||||
|
|
||||||
local function summ_time()
|
local function time()
|
||||||
focus_events = clean_from(clean_to + 1, focus_events)
|
focus_events = clean_from(clean_to + 1, focus_events)
|
||||||
clean_to = #focus_events
|
clean_to = #focus_events
|
||||||
|
|
||||||
@ -68,72 +65,37 @@ local function summ_time()
|
|||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
local function fmt_time(time)
|
local function log_time()
|
||||||
local str = ""
|
print(time())
|
||||||
|
|
||||||
local days = math.floor(time / (60 * 60 * 24))
|
|
||||||
if days ~= 0 then
|
|
||||||
str = str .. days .. "d"
|
|
||||||
end
|
|
||||||
|
|
||||||
time = time % (60 * 60 * 24)
|
|
||||||
|
|
||||||
local hours = math.floor(time / (60 * 60))
|
|
||||||
if hours ~= 0 then
|
|
||||||
str = str .. hours .. "h"
|
|
||||||
end
|
|
||||||
|
|
||||||
time = time % (60 * 60)
|
|
||||||
|
|
||||||
local minutes = math.floor(time / 60)
|
|
||||||
if minutes ~= 0 then
|
|
||||||
str = str .. minutes .. "m"
|
|
||||||
end
|
|
||||||
|
|
||||||
local seconds = time % (60)
|
|
||||||
if seconds ~= 0 then
|
|
||||||
str = str .. seconds .. "s"
|
|
||||||
end
|
|
||||||
|
|
||||||
return str
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function log_total_time()
|
|
||||||
local times = {}
|
|
||||||
times[username] = summ_time()
|
|
||||||
|
|
||||||
local file = io.open(filename, "r")
|
|
||||||
|
|
||||||
-- if file exists read
|
|
||||||
if file ~= nil then
|
|
||||||
local history = TOML.parse(file:read("*a"))
|
|
||||||
file:close()
|
|
||||||
|
|
||||||
|
|
||||||
for _, day in pairs(history) do
|
|
||||||
for user, time in pairs(day) do
|
|
||||||
if times[user] == nil then
|
|
||||||
times[user] = 0
|
|
||||||
end
|
|
||||||
times[user] = times[user] + time
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for user, time in pairs(times) do
|
|
||||||
print(user, fmt_time(time))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function log_time_table()
|
local function log_time_table()
|
||||||
for i, e in pairs(focus_events) do
|
for i, e in pairs(focus_events) do
|
||||||
print(i, e.event, os.date("%H:%M:%S", e.time))
|
print(i, e.event, os.date("%H:%M:%S", e.time))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function focus_gained()
|
||||||
|
print("Huiii Fokus")
|
||||||
|
|
||||||
|
table.insert(focus_events, {
|
||||||
|
time = os.time(),
|
||||||
|
event = "gain",
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
local function focus_lost()
|
||||||
|
print("Hokus pokus fort ist der fokus")
|
||||||
|
|
||||||
|
table.insert(focus_events, {
|
||||||
|
time = os.time(),
|
||||||
|
event = "lose",
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
local function persist()
|
local function persist()
|
||||||
|
local filename = ".timer.toml"
|
||||||
|
local username = trim(os.getenv("USER")) .. "_at_" .. trim(io.popen("hostname -s"):read("*a"))
|
||||||
local today = os.date("%y-%m-%d", os.time())
|
local today = os.date("%y-%m-%d", os.time())
|
||||||
local table = {}
|
local table = {}
|
||||||
|
|
||||||
@ -147,12 +109,12 @@ local function persist()
|
|||||||
|
|
||||||
-- write time to table
|
-- write time to table
|
||||||
if table[today] ~= nil and table[today][username] ~= nil then
|
if table[today] ~= nil and table[today][username] ~= nil then
|
||||||
table[today][username] = table[today][username] + summ_time()
|
table[today][username] = table[today][username] + time()
|
||||||
else
|
else
|
||||||
if table[today] == nil then
|
if table[today] == nil then
|
||||||
table[today] = {}
|
table[today] = {}
|
||||||
end
|
end
|
||||||
table[today][username] = summ_time()
|
table[today][username] = time()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- write table to file
|
-- write table to file
|
||||||
@ -170,19 +132,6 @@ local function persist()
|
|||||||
focus_events = {}
|
focus_events = {}
|
||||||
focus_gained()
|
focus_gained()
|
||||||
end
|
end
|
||||||
local function focus_gained()
|
|
||||||
table.insert(focus_events, {
|
|
||||||
time = os.time(),
|
|
||||||
event = "gain",
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
local function focus_lost()
|
|
||||||
table.insert(focus_events, {
|
|
||||||
time = os.time(),
|
|
||||||
event = "lose",
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
local function setup()
|
local function setup()
|
||||||
vim.api.nvim_create_autocmd("VimEnter",
|
vim.api.nvim_create_autocmd("VimEnter",
|
||||||
@ -194,7 +143,7 @@ local function setup()
|
|||||||
|
|
||||||
vim.api.nvim_create_user_command(
|
vim.api.nvim_create_user_command(
|
||||||
'Timer', -- The name of the command (accessible via :TimerStart)
|
'Timer', -- The name of the command (accessible via :TimerStart)
|
||||||
log_total_time,
|
log_time,
|
||||||
{ nargs = 0 } -- No arguments for this command (you can configure this later)
|
{ nargs = 0 } -- No arguments for this command (you can configure this later)
|
||||||
)
|
)
|
||||||
vim.api.nvim_create_user_command(
|
vim.api.nvim_create_user_command(
|
||||||
|
Loading…
Reference in New Issue
Block a user