diff --git a/app_state.go b/app_state.go index 2c977f6..71f9e95 100644 --- a/app_state.go +++ b/app_state.go @@ -226,6 +226,10 @@ func (a *AppState) initialize() { []string{"--h - Print this message"}, a.opPrintUsage, ) + a.addOperation("editor", + []string{"editor - Open todo.txt file in your editor"}, + a.opEditor, + ) a.directory = a.config.Get("directory") a.fileTodo = a.config.Get("todofile") a.fileDone = a.config.Get("donefile") diff --git a/task_ops.go b/task_ops.go index 12bc294..3e1bd75 100644 --- a/task_ops.go +++ b/task_ops.go @@ -2,12 +2,31 @@ package main import ( "fmt" + "os" + "os/exec" "strconv" "strings" todotxt "git.bullercodeworks.com/brian/go-todotxt" ) +func (a *AppState) opEditor(args []string) int { + editor := os.Getenv("EDITOR") + if editor == "" { + fmt.Println("No EDITOR set") + return 1 + } + fmt.Println("Starting", editor, a.getTodoFile()) + c := exec.Command(editor, a.getTodoFile()) + c.Stdin = os.Stdin + c.Stdout = os.Stdout + if err := c.Run(); err != nil { + fmt.Println(err) + return 1 + } + return 0 +} + func (a *AppState) opI3Status(args []string) int { var filterString string state := "Idle"