Add 'editor' op

This commit is contained in:
Brian Buller 2023-09-15 09:11:44 -05:00
parent 4e4ef313f2
commit 53d0ec2550
2 changed files with 23 additions and 0 deletions

View File

@ -226,6 +226,10 @@ func (a *AppState) initialize() {
[]string{"--h - Print this message"}, []string{"--h - Print this message"},
a.opPrintUsage, a.opPrintUsage,
) )
a.addOperation("editor",
[]string{"editor - Open todo.txt file in your editor"},
a.opEditor,
)
a.directory = a.config.Get("directory") a.directory = a.config.Get("directory")
a.fileTodo = a.config.Get("todofile") a.fileTodo = a.config.Get("todofile")
a.fileDone = a.config.Get("donefile") a.fileDone = a.config.Get("donefile")

View File

@ -2,12 +2,31 @@ package main
import ( import (
"fmt" "fmt"
"os"
"os/exec"
"strconv" "strconv"
"strings" "strings"
todotxt "git.bullercodeworks.com/brian/go-todotxt" 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 { func (a *AppState) opI3Status(args []string) int {
var filterString string var filterString string
state := "Idle" state := "Idle"