all repos

init.lua @ 3267499312591bf8d430e063134ad652f9d4b26d

my nvim config
1 files changed, 47 insertions(+), 1 deletions(-)
feat(notes): auto commit on every change

+ added git integration
+ auto init repo if needed
+ auto stage and commit changes on every file write
  - commit name is current date and time
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