about summary refs log tree commit diff
path: root/git_sync.lua
diff options
context:
space:
mode:
authoriurii plugatarov <[email protected]>2024-08-02 23:01:35 +0200
committeriurii plugatarov <[email protected]>2024-08-02 23:01:35 +0200
commitf4a1319352d466308cd85eb1263aef9fd2c54293 (patch)
tree335eac92b9f9f47cec3d9bf60d7699d9fa8d66d7 /git_sync.lua
downloadsketchbook.nvim-f4a1319352d466308cd85eb1263aef9fd2c54293.tar.gz
init
Diffstat (limited to 'git_sync.lua')
-rw-r--r--git_sync.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/git_sync.lua b/git_sync.lua
new file mode 100644
index 0000000..d19f024
--- /dev/null
+++ b/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