From f9e9eb3049fd05c5f2f7145dd1a232be4ade35a8 Mon Sep 17 00:00:00 2001 From: John Costa Date: Tue, 24 Oct 2023 23:57:23 +0100 Subject: [PATCH] FEAT: Smalls script to create obsidean tasks --- Scripts/CreateTask.go | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Scripts/CreateTask.go diff --git a/Scripts/CreateTask.go b/Scripts/CreateTask.go new file mode 100644 index 00000000..07c1c010 --- /dev/null +++ b/Scripts/CreateTask.go @@ -0,0 +1,49 @@ +package main + +import ( + "fmt" + "os" +) + +var TEMPLATE_PATH = "/Obsidian/NotesBackup/Templates/Project Template.md" +var OBSIDEAN_PATH = "/Obsidian/NotesBackup/Projects/Life/" + +func main() { + dirname, err := os.UserHomeDir() + if err != nil { + panic(err) + } + + TEMPLATE_PATH = dirname + TEMPLATE_PATH + OBSIDEAN_PATH = dirname + OBSIDEAN_PATH + + args := os.Args + + if len(args) < 2 { + panic("Command incorrect, expected: `go run script.go taskName` at least") + } + + name := args[1] + description := "" + + for i := 2; i < len(args); i++ { + description += args[i] + " " + } + description = description[:len(description) - 1] + + CreateTask(name, description) +} + +func CreateTask(name string, description string) { + templateContent, err := os.ReadFile(TEMPLATE_PATH) + if err != nil { + panic(err) + } + + fileContent := fmt.Sprintf("%s\n%s", string(templateContent), description) + + err = os.WriteFile(OBSIDEAN_PATH + name + ".md", []byte(fileContent), 0644) + if err != nil { + panic(err) + } +}