Fix Editor Command

This commit is contained in:
Brian Buller 2022-01-21 16:49:05 -06:00
parent 45d13e7052
commit b0f5e928d9
2 changed files with 30 additions and 2 deletions

View File

@ -27,6 +27,10 @@ func (p *Program) Initialize() error {
return nil return nil
} }
func (p *Program) GetTimerFilePath() string {
return p.timerPath
}
func (p *Program) LoadTimerList() error { func (p *Program) LoadTimerList() error {
var err error var err error
var tl timertxt.TimerList var tl timertxt.TimerList
@ -43,6 +47,10 @@ func (p *Program) WriteTimerList() error {
return p.TimerList.WriteToFilename(p.timerPath) return p.TimerList.WriteToFilename(p.timerPath)
} }
func (p *Program) GetDoneFilePath() string {
return p.donePath
}
func (p *Program) LoadDoneList() error { func (p *Program) LoadDoneList() error {
var err error var err error
var tl timertxt.TimerList var tl timertxt.TimerList

View File

@ -6,7 +6,10 @@ package cmd
import ( import (
"fmt" "fmt"
"os"
"os/exec"
"git.bullercodeworks.com/brian/gime/cli"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -22,6 +25,23 @@ func init() {
} }
func opEditor(cmd *cobra.Command, args []string) error { func opEditor(cmd *cobra.Command, args []string) error {
fmt.Println("editor called") p := cli.Program{}
return nil 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()
} }