From f24a3ab9744a3f50eb8cacc06d4ef4c5f96875db Mon Sep 17 00:00:00 2001 From: iurii plugatarov Date: Sat, 3 Aug 2024 00:19:11 +0300 Subject: fix --- lua/sketchbook/git_sync.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lua/sketchbook/git_sync.lua (limited to 'lua/sketchbook/git_sync.lua') diff --git a/lua/sketchbook/git_sync.lua b/lua/sketchbook/git_sync.lua new file mode 100644 index 0000000..d19f024 --- /dev/null +++ b/lua/sketchbook/git_sync.lua @@ -0,0 +1,36 @@ +local M = {} + +function M.is_git_repo(path) + local git_dir = vim.fn.systemlist("git -C " .. path .. " rev-parse --is-inside-work-tree")[1] + return git_dir == "true" +end + +function M.commit_notes() + local notes_dir = vim.g.notes_directory or "~/notes/" + notes_dir = vim.fn.expand(notes_dir) + + if not M.is_git_repo(notes_dir) then + vim.notify("Note folder is not a Git repository.", vim.log.levels.WARN) + return + end + + local commit_message = "Update notes: " .. os.date "%Y-%m-%d %H:%M:%S" + vim.fn.system("git -C " .. notes_dir .. " add .") + vim.fn.system("git -C " .. notes_dir .. " commit -m '" .. commit_message .. "'") + vim.notify("Notes committed to Git repository.", vim.log.levels.INFO) +end + +function M.push_notes() + local notes_dir = vim.g.notes_directory or "~/notes/" + notes_dir = vim.fn.expand(notes_dir) + + if not M.is_git_repo(notes_dir) then + vim.notify("Note folder is not a Git repository.", vim.log.levels.WARN) + return + end + + vim.fn.system("git -C " .. notes_dir .. " push") + vim.notify("Notes pushed to remote repository.", vim.log.levels.INFO) +end + +return M -- cgit 1.4.1-2-gfad0