diff --git a/cli/cli.go b/cli/cli.go index 52bf93a..52953cd 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -27,6 +27,10 @@ func (p *Program) Initialize() error { return nil } +func (p *Program) GetTimerFilePath() string { + return p.timerPath +} + func (p *Program) LoadTimerList() error { var err error var tl timertxt.TimerList @@ -43,6 +47,10 @@ func (p *Program) WriteTimerList() error { return p.TimerList.WriteToFilename(p.timerPath) } +func (p *Program) GetDoneFilePath() string { + return p.donePath +} + func (p *Program) LoadDoneList() error { var err error var tl timertxt.TimerList diff --git a/cmd/editor.go b/cmd/editor.go index 318e0d0..52d787e 100644 --- a/cmd/editor.go +++ b/cmd/editor.go @@ -6,7 +6,10 @@ package cmd import ( "fmt" + "os" + "os/exec" + "git.bullercodeworks.com/brian/gime/cli" "github.com/spf13/cobra" ) @@ -22,6 +25,23 @@ func init() { } func opEditor(cmd *cobra.Command, args []string) error { - fmt.Println("editor called") - return nil + p := cli.Program{} + if err := p.Initialize(); err != nil { + return err + } + file := p.GetTimerFilePath() + if len(args) > 0 { + if args[0] == "d" || args[0] == "done" { + file = p.GetDoneFilePath() + } + } + editor := os.Getenv("EDITOR") + if editor == "" { + return fmt.Errorf("No EDITOR set") + } + fmt.Println("Starting", editor, file) + c := exec.Command(editor, file) + c.Stdin = os.Stdin + c.Stdout = os.Stdout + return c.Run() }