-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (50 loc) · 1.44 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"gopkg.in/yaml.v2"
)
type Config struct {
TemplatePath string `yaml:"templatePath"`
}
func main() {
configPath := filepath.Join(os.Getenv("HOME"), ".config", "zet.yml")
// Read the config file
data, err := ioutil.ReadFile(configPath)
if err != nil {
log.Fatalf("Error reading config file: %v", err)
}
// Parse the config file
var config Config
err = yaml.Unmarshal(data, &config)
if err != nil {
log.Fatalf("Error parsing config file: %v", err)
}
// Read the template content
templateContent, err := ioutil.ReadFile(config.TemplatePath)
if err != nil {
log.Fatalf("Error reading template file: %v", err)
}
// Create a temporary file for the new document
tmpFile, err := ioutil.TempFile("", "zet-*.md")
if err != nil {
log.Fatalf("Error creating temporary file: %v", err)
}
defer os.Remove(tmpFile.Name())
// Write the template content to the temporary file
if _, err := tmpFile.Write(templateContent); err != nil {
log.Fatalf("Error writing to temporary file: %v", err)
}
tmpFile.Close()
// Open the temporary file in nvim
cmd := exec.Command("nvim", tmpFile.Name())
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
log.Fatalf("Error opening file in nvim: %v", err)
}
}