|
|
|
@ -9,7 +9,6 @@ import (
|
|
|
|
|
"log"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"path"
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
@ -44,18 +43,17 @@ var noteCmd = &cobra.Command{
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file_path := path.Join(os.TempDir(), "diary_note.md")
|
|
|
|
|
file, err := os.Create(file_path)
|
|
|
|
|
temp_file, err := ioutil.TempFile(os.TempDir(), "diary_note.*.md")
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
file.Close()
|
|
|
|
|
defer os.Remove(temp_file.Name())
|
|
|
|
|
|
|
|
|
|
var editor = os.Getenv("EDITOR")
|
|
|
|
|
if editor == "" {
|
|
|
|
|
editor = "nano"
|
|
|
|
|
}
|
|
|
|
|
editor_cmd := exec.Command(editor, file_path)
|
|
|
|
|
editor_cmd := exec.Command(editor, temp_file.Name())
|
|
|
|
|
editor_cmd.Stdin = os.Stdin
|
|
|
|
|
editor_cmd.Stdout = os.Stdout
|
|
|
|
|
editor_cmd.Stderr = os.Stderr
|
|
|
|
@ -69,11 +67,10 @@ var noteCmd = &cobra.Command{
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content, err := ioutil.ReadFile(file_path)
|
|
|
|
|
content, err := ioutil.ReadFile(temp_file.Name())
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
os.Remove(file_path)
|
|
|
|
|
App.NewDiaryEntryNote(int64(entry_id), string(content))
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|