From 97fb0206cff4b3cdd8dded346ddcba56b8b3f1ff Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Fri, 15 Dec 2023 07:58:31 +0100 Subject: [PATCH] try neovim --- .gitignore | 1 + main.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6b584e8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +content \ No newline at end of file diff --git a/main.go b/main.go index 155b9bc..4815a74 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,59 @@ package main -import "fmt" +import ( + "fmt" + "log" + "os" + "os/exec" + "path/filepath" + "time" +) + +type Scene struct { + Path string +} func main() { - fmt.Println("Hoi") + + // Start Neovim with a server name + cmd := exec.Command("nvim", "--servername", "NVIM_SERVER", tempFile.Name()) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Start() + if err != nil { + log.Fatal(err) + } + + // Wait for Neovim to start + time.Sleep(time.Second) + + // Send a command to the running Neovim instance + cmd = exec.Command("nvim", "--servername", "NVIM_SERVER", "--remote-send", ":edit /path/to/new/file") + err = cmd.Run() + if err != nil { + log.Fatal(err) + } + +} + +func getScenes() ([]Scene, error) { + scenes := make([]Scene, 0) + root := "content" + err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if !info.IsDir() { + if filepath.Ext(path) == ".md" { + scenes = append(scenes, Scene{Path: path}) + } + } + return nil + }) + if err != nil { + fmt.Printf("error walking the path %v: %v\n", root, err) + } + + return scenes, nil }