Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
be98b94f97 | |||
0dbfa8f422 | |||
ad454d9cf8 | |||
![]() |
81f137ee1a | ||
![]() |
bac26868d8 | ||
![]() |
9c2ac4bc46 |
12
.timer.toml
12
.timer.toml
@ -1,3 +1,13 @@
|
|||||||
## dates and their corresponding seconds been here :)
|
## dates and their corresponding seconds been here :)
|
||||||
[24-10-07]
|
[24-10-07]
|
||||||
u80864958_at_u80864958 = 432
|
u80864958_at_u80864958 = 432
|
||||||
|
[24-10-08]
|
||||||
|
u80864958_at_u80864958 = 425
|
||||||
|
[24-10-11]
|
||||||
|
u80864958_at_u80864958 = 6021
|
||||||
|
[24-10-15]
|
||||||
|
schreifuchs_at_archlinux = 128
|
||||||
|
[24-11-06]
|
||||||
|
schreifuchs_at_archibald = 18
|
||||||
|
[24-12-25]
|
||||||
|
schreifuchs_at_archibald = 204
|
||||||
|
40
README.md
40
README.md
@ -5,3 +5,43 @@ Timer times the time it took you to realize your project
|
|||||||
Counts the time in your editor inside on directory.
|
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.
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
You must have the ```hostname``` util installed on your system.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
## on Arch based distros:
|
||||||
|
sudo pacmn -S inetutils
|
||||||
|
```
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Lunar vim:
|
||||||
|
```lua
|
||||||
|
lvim.plugins = {
|
||||||
|
{
|
||||||
|
"schreifuchs/timer",
|
||||||
|
url = "https://git.schreifuchs.ch/schreifuchs/timer.git",
|
||||||
|
config = function()
|
||||||
|
require('timer').setup()
|
||||||
|
end
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
function trim(s)
|
local function trim(s)
|
||||||
return (s:gsub("^%s*(.-)%s*$", "%1"))
|
return (s:gsub("^%s*(.-)%s*$", "%1"))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ local clean_to = 1
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function clean_from(from, events)
|
local function clean_from(from, events) -- cleans the events
|
||||||
local clean_events = {}
|
local clean_events = {}
|
||||||
|
|
||||||
-- coppy until from
|
-- coppy until from
|
||||||
@ -46,7 +46,7 @@ local function clean_from(from, events)
|
|||||||
return clean_events
|
return clean_events
|
||||||
end
|
end
|
||||||
|
|
||||||
local function summ_time()
|
local function summ_time() --returns time in seconds from the fous events
|
||||||
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
|
||||||
|
|
||||||
@ -107,6 +107,7 @@ 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
|
||||||
@ -144,17 +145,43 @@ local function focus_lost()
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function next_lowest_time_file()
|
||||||
|
local file_path = filename
|
||||||
|
|
||||||
local function persist()
|
for _ = 1, 10, 1 do
|
||||||
|
local f = io.open(file_path)
|
||||||
|
|
||||||
|
if f ~= nil then
|
||||||
|
return file_path
|
||||||
|
end
|
||||||
|
|
||||||
|
file_path = "../" .. file_path
|
||||||
|
end
|
||||||
|
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
|
||||||
|
local function persist(force)
|
||||||
|
return function()
|
||||||
local TOML = require("toml")
|
local TOML = require("toml")
|
||||||
local today = os.date("%y-%m-%d", os.time())
|
local today = os.date("%y-%m-%d", os.time())
|
||||||
local table = {}
|
local table = {}
|
||||||
|
local file_path = filename
|
||||||
|
|
||||||
local file = io.open(filename, "r")
|
local file = io.open(file_path, "r")
|
||||||
-- if file exists read
|
-- if file exists read
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
table = TOML.parse(file:read("*a"))
|
table = TOML.parse(file:read("*a"))
|
||||||
file:close()
|
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
|
end
|
||||||
|
|
||||||
-- write time to table
|
-- write time to table
|
||||||
@ -168,29 +195,31 @@ local function persist()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- write table to file
|
-- write table to file
|
||||||
file = io.open(filename, "w")
|
file = io.open(file_path, "w")
|
||||||
if file == nil then
|
if file == nil then
|
||||||
error("can't write to .timer file")
|
error("can't write to .timer file")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local tml = TOML.encode(table)
|
local tml = TOML.encode(table)
|
||||||
print(tml)
|
|
||||||
|
|
||||||
file:write("## dates and their corresponding seconds been here :)\n", tml, "\n")
|
file:write("## dates and their corresponding seconds been here :)\n", tml, "\n")
|
||||||
file:close()
|
file:close()
|
||||||
|
|
||||||
|
print("Timer saved successfully :-)")
|
||||||
|
|
||||||
--reset timer
|
--reset timer
|
||||||
clean_to = 1
|
clean_to = 1
|
||||||
focus_events = {}
|
focus_events = {}
|
||||||
focus_gained()
|
focus_gained()
|
||||||
end
|
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 })
|
{ group = augroup, desc = "Persist timer", once = true, callback = persist(false) })
|
||||||
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 })
|
||||||
|
|
||||||
@ -206,7 +235,7 @@ local function setup()
|
|||||||
)
|
)
|
||||||
vim.api.nvim_create_user_command(
|
vim.api.nvim_create_user_command(
|
||||||
'TimerSave',
|
'TimerSave',
|
||||||
persist,
|
persist(true),
|
||||||
{ 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
|
||||||
|
12
lua/toml.lua
12
lua/toml.lua
@ -564,7 +564,15 @@ TOML.encode = function(tbl)
|
|||||||
local cache = {}
|
local cache = {}
|
||||||
|
|
||||||
local function parse(tbl)
|
local function parse(tbl)
|
||||||
for k, v in pairs(tbl) do
|
local tbl_keys = {}
|
||||||
|
for k in pairs(tbl) do
|
||||||
|
table.insert(tbl_keys, k)
|
||||||
|
end
|
||||||
|
table.sort(tbl_keys)
|
||||||
|
|
||||||
|
|
||||||
|
for _, k in pairs(tbl_keys) do
|
||||||
|
local v = tbl[k]
|
||||||
if type(v) == "boolean" then
|
if type(v) == "boolean" then
|
||||||
toml = toml .. k .. " = " .. tostring(v) .. "\n"
|
toml = toml .. k .. " = " .. tostring(v) .. "\n"
|
||||||
elseif type(v) == "number" then
|
elseif type(v) == "number" then
|
||||||
@ -572,7 +580,7 @@ TOML.encode = function(tbl)
|
|||||||
elseif type(v) == "string" then
|
elseif type(v) == "string" then
|
||||||
local quote = '"'
|
local quote = '"'
|
||||||
v = v:gsub("\\", "\\\\")
|
v = v:gsub("\\", "\\\\")
|
||||||
|
--
|
||||||
-- if the string has any line breaks, make it multiline
|
-- if the string has any line breaks, make it multiline
|
||||||
if v:match("^\n(.*)$") then
|
if v:match("^\n(.*)$") then
|
||||||
quote = quote:rep(3)
|
quote = quote:rep(3)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user