narratio/main.go

60 lines
1.1 KiB
Go
Raw Normal View History

2023-12-15 07:18:39 +01:00
package main
2023-12-15 07:58:31 +01:00
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"time"
)
type Scene struct {
Path string
}
2023-12-15 07:18:39 +01:00
func main() {
2023-12-15 07:58:31 +01:00
// 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<CR>")
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
2023-12-15 07:18:39 +01:00
}