From 59c4d132b242f089bbbd9530387a063a57def1f5 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 25 Sep 2025 23:30:22 +0100 Subject: [PATCH] Commit the zettel after saving Signed-off-by: Oliver Davies --- internal/lib/git.go | 25 ++++++++++++++++++++++++- internal/lib/zet.go | 8 ++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/internal/lib/git.go b/internal/lib/git.go index 30abd4a..4ffb8a2 100644 --- a/internal/lib/git.go +++ b/internal/lib/git.go @@ -1,6 +1,18 @@ package lib -import "os/exec" +import ( + "os" + "os/exec" + "strconv" +) + +func CommitZettel(id int, title string) { + idString := strconv.Itoa(id) + + runGitCommand("add", idString) + runGitCommand("commit", "-m", title) + runGitCommand("push") +} func execGitCommand(parts ...string) (string, error) { args := append([]string{"-C", GetZetDir()}, parts...) @@ -10,3 +22,14 @@ func execGitCommand(parts ...string) (string, error) { return string(output), err } + +func runGitCommand(parts ...string) { + args := append([]string{"-C", GetZetDir()}, parts...) + command := exec.Command("git", args...) + + command.Stderr = os.Stderr + command.Stdin = os.Stdin + command.Stdout = os.Stdout + + command.Run() +} diff --git a/internal/lib/zet.go b/internal/lib/zet.go index 2e2f50d..766240e 100644 --- a/internal/lib/zet.go +++ b/internal/lib/zet.go @@ -16,6 +16,8 @@ func EditZet(id int) { zetPath := path.Join(GetZetDir(), strconv.Itoa(id), "index.adoc") EditFile(zetPath) + + onSave(id) } func GetAllZets() []int { @@ -136,3 +138,9 @@ func getTitleFromFile(filePath string) string { return "" } + +func onSave(id int) { + title := getTitle(id) + + CommitZettel(id, title) +}