Compare commits
No commits in common. "81f137ee1a11000c12df6f8720c0510b84c87386" and "9c2ac4bc46e103e54c748ec0aae220af7d48c9a6" have entirely different histories.
81f137ee1a
...
9c2ac4bc46
@ -1,7 +1,5 @@
|
|||||||
## dates and their corresponding seconds been here :)
|
## dates and their corresponding seconds been here :)
|
||||||
[24-10-08]
|
|
||||||
u80864958_at_u80864958 = 425
|
|
||||||
[24-10-11]
|
|
||||||
u80864958_at_u80864958 = 6021
|
|
||||||
[24-10-07]
|
[24-10-07]
|
||||||
u80864958_at_u80864958 = 432
|
u80864958_at_u80864958 = 432
|
||||||
|
[24-10-08]
|
||||||
|
u80864958_at_u80864958 = 372
|
||||||
|
16
README.md
16
README.md
@ -6,22 +6,6 @@ Counts the time in your editor inside on directory.
|
|||||||
Not beeing inside the editor for less than 5 minutes gets counted as beeing
|
Not beeing inside the editor for less than 5 minutes gets counted as beeing
|
||||||
inside the editor.
|
inside the editor.
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
### Show time
|
|
||||||
|
|
||||||
```:Timer```: prints the time inside this directory. If ```.timer.toml``` exists it get's included.
|
|
||||||
|
|
||||||
```:TimerLog```: logs the current time table.
|
|
||||||
|
|
||||||
|
|
||||||
### Save time
|
|
||||||
|
|
||||||
Time gets automatically saved, when neovim is closed. Given that the ```.timer.toml``` file exists.
|
|
||||||
If it doesn't Timer searches the next 10 higher directories for one. If there isn't one either nothing get's persisted.
|
|
||||||
|
|
||||||
```:TimerSave```: saves the current time to ```.timer.toml```. If the file doesn't exist it gets created.
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Lunar vim:
|
Lunar vim:
|
||||||
|
107
lua/timer.lua
107
lua/timer.lua
@ -1,4 +1,4 @@
|
|||||||
local function trim(s)
|
function trim(s)
|
||||||
return (s:gsub("^%s*(.-)%s*$", "%1"))
|
return (s:gsub("^%s*(.-)%s*$", "%1"))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -107,7 +107,6 @@ local function log_total_time()
|
|||||||
local history = require("toml").parse(file:read("*a"))
|
local history = require("toml").parse(file:read("*a"))
|
||||||
file:close()
|
file:close()
|
||||||
|
|
||||||
print("Time for:", filename)
|
|
||||||
|
|
||||||
for _, day in pairs(history) do
|
for _, day in pairs(history) do
|
||||||
for user, time in pairs(day) do
|
for user, time in pairs(day) do
|
||||||
@ -145,81 +144,53 @@ local function focus_lost()
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
local function next_lowest_time_file()
|
|
||||||
local file_path = filename
|
|
||||||
|
|
||||||
for _ = 1, 10, 1 do
|
local function persist()
|
||||||
local f = io.open(file_path)
|
local TOML = require("toml")
|
||||||
|
local today = os.date("%y-%m-%d", os.time())
|
||||||
|
local table = {}
|
||||||
|
|
||||||
if f ~= nil then
|
local file = io.open(filename, "r")
|
||||||
return file_path
|
-- if file exists read
|
||||||
end
|
if file ~= nil then
|
||||||
|
table = TOML.parse(file:read("*a"))
|
||||||
file_path = "../" .. file_path
|
|
||||||
end
|
|
||||||
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
local function persist(force)
|
|
||||||
return function()
|
|
||||||
local TOML = require("toml")
|
|
||||||
local today = os.date("%y-%m-%d", os.time())
|
|
||||||
local table = {}
|
|
||||||
local file_path = filename
|
|
||||||
|
|
||||||
local file = io.open(file_path, "r")
|
|
||||||
-- if file exists read
|
|
||||||
if file ~= nil then
|
|
||||||
table = TOML.parse(file:read("*a"))
|
|
||||||
file:close()
|
|
||||||
else
|
|
||||||
if not force then
|
|
||||||
file_path = next_lowest_time_file()
|
|
||||||
if file_path == "" then
|
|
||||||
print("No save file found. To create a new save file run :TimerSave")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
print("Save file found:", file_path)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- write time to table
|
|
||||||
if table[today] ~= nil and table[today][username] ~= nil then
|
|
||||||
table[today][username] = table[today][username] + summ_time()
|
|
||||||
else
|
|
||||||
if table[today] == nil then
|
|
||||||
table[today] = {}
|
|
||||||
end
|
|
||||||
table[today][username] = summ_time()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- write table to file
|
|
||||||
file = io.open(file_path, "w")
|
|
||||||
if file == nil then
|
|
||||||
error("can't write to .timer file")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local tml = TOML.encode(table)
|
|
||||||
|
|
||||||
file:write("## dates and their corresponding seconds been here :)\n", tml, "\n")
|
|
||||||
file:close()
|
file:close()
|
||||||
|
|
||||||
print("Timer saved successfully :-)")
|
|
||||||
|
|
||||||
--reset timer
|
|
||||||
clean_to = 1
|
|
||||||
focus_events = {}
|
|
||||||
focus_gained()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- write time to table
|
||||||
|
if table[today] ~= nil and table[today][username] ~= nil then
|
||||||
|
table[today][username] = table[today][username] + summ_time()
|
||||||
|
else
|
||||||
|
if table[today] == nil then
|
||||||
|
table[today] = {}
|
||||||
|
end
|
||||||
|
table[today][username] = summ_time()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- write table to file
|
||||||
|
file = io.open(filename, "w")
|
||||||
|
if file == nil then
|
||||||
|
error("can't write to .timer file")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local tml = TOML.encode(table)
|
||||||
|
print(tml)
|
||||||
|
|
||||||
|
file:write("## dates and their corresponding seconds been here :)\n", tml, "\n")
|
||||||
|
file:close()
|
||||||
|
|
||||||
|
--reset timer
|
||||||
|
clean_to = 1
|
||||||
|
focus_events = {}
|
||||||
|
focus_gained()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setup()
|
local function setup()
|
||||||
vim.api.nvim_create_autocmd("VimEnter",
|
vim.api.nvim_create_autocmd("VimEnter",
|
||||||
{ group = augroup, desc = "Start Timer", once = true, callback = focus_gained })
|
{ group = augroup, desc = "Start Timer", once = true, callback = focus_gained })
|
||||||
vim.api.nvim_create_autocmd("ExitPre",
|
vim.api.nvim_create_autocmd("ExitPre",
|
||||||
{ group = augroup, desc = "Persist timer", once = true, callback = persist(false) })
|
{ group = augroup, desc = "Persist timer", once = true, callback = persist })
|
||||||
vim.api.nvim_create_autocmd("FocusGained", { group = augroup, callback = focus_gained })
|
vim.api.nvim_create_autocmd("FocusGained", { group = augroup, callback = focus_gained })
|
||||||
vim.api.nvim_create_autocmd("FocusLost", { group = augroup, callback = focus_lost })
|
vim.api.nvim_create_autocmd("FocusLost", { group = augroup, callback = focus_lost })
|
||||||
|
|
||||||
@ -235,7 +206,7 @@ local function setup()
|
|||||||
)
|
)
|
||||||
vim.api.nvim_create_user_command(
|
vim.api.nvim_create_user_command(
|
||||||
'TimerSave',
|
'TimerSave',
|
||||||
persist(true),
|
persist,
|
||||||
{ nargs = 0 } -- No arguments for this command (you can configure this later)
|
{ nargs = 0 } -- No arguments for this command (you can configure this later)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user