1 files changed,
47 insertions(+),
1 deletions(-)
Author:
Smirnov Oleksandr
ss2316544@gmail.com
Committed at:
2024-05-10 14:30:47 +0300
Parent:
8132a45
M
lua/scratch/notes.lua
@@ -2,10 +2,52 @@ local notes = {}
local config = { file_extenson = ".md", - data_path = ("%s/ol_notes"):format(vim.fn.stdpath "data"), + data_path = ("%s/ol_notes/"):format(vim.fn.stdpath "data"), open_cmd = "e", } +local git = {} + +---@param cmd table +function git.cmd(cmd) + vim.system( + { "git", "-C", config.data_path, unpack(cmd) }, + { timeout = 120 }, + function(o) + if cmd[1] == "commit" and o.code ~= 0 then + vim.print "couldnt commit" + end + end + ) +end + +function git.init() + if vim.fn.isdirectory(config.data_path .. "/.git") == 0 then + git.cmd { "init" } + end +end + +function git.commit() + git.init() + git.cmd { "add", "--all" } + git.cmd { + "commit", + "-m", + os.date "%Y-%m-%d %H:%M:%S", + } +end + +---@param bufnr number +function git.aucmd(bufnr) + vim.api.nvim_create_autocmd("BufWritePost", { + group = vim.api.nvim_create_augroup("ol_notes_commit", { clear = true }), + buffer = bufnr, + callback = function() + git.commit() + end, + }) +end + ---@return string ---@private function notes.get_project_path()@@ -29,6 +71,8 @@ vim.cmd[config.open_cmd] {
args = { notes.get_note_path(notes.get_project_path()) }, bang = true, } + + git.aucmd(vim.fn.bufnr()) end function notes.open()@@ -36,6 +80,8 @@ vim.cmd[config.open_cmd] {
args = { config.data_path .. "/notes.md" }, bang = true, } + + git.aucmd(vim.fn.bufnr()) end return notes