Commit the zettel after saving

Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
Oliver Davies 2025-09-25 23:30:22 +01:00
parent 2537b4db9e
commit 59c4d132b2
2 changed files with 32 additions and 1 deletions

View file

@ -1,6 +1,18 @@
package lib 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) { func execGitCommand(parts ...string) (string, error) {
args := append([]string{"-C", GetZetDir()}, parts...) args := append([]string{"-C", GetZetDir()}, parts...)
@ -10,3 +22,14 @@ func execGitCommand(parts ...string) (string, error) {
return string(output), err 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()
}

View file

@ -16,6 +16,8 @@ func EditZet(id int) {
zetPath := path.Join(GetZetDir(), strconv.Itoa(id), "index.adoc") zetPath := path.Join(GetZetDir(), strconv.Itoa(id), "index.adoc")
EditFile(zetPath) EditFile(zetPath)
onSave(id)
} }
func GetAllZets() []int { func GetAllZets() []int {
@ -136,3 +138,9 @@ func getTitleFromFile(filePath string) string {
return "" return ""
} }
func onSave(id int) {
title := getTitle(id)
CommitZettel(id, title)
}