60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"time"
|
|
)
|
|
|
|
type Scene struct {
|
|
Path string
|
|
}
|
|
|
|
func main() {
|
|
|
|
// 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
|
|
}
|