48 lines
917 B
Go
48 lines
917 B
Go
/*
|
|
Copyright © 2022 Brian Buller <brian@bullercodeworks.com>
|
|
|
|
*/
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
|
|
"git.bullercodeworks.com/brian/gime/cli"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// editorCmd represents the editor command
|
|
var editorCmd = &cobra.Command{
|
|
Use: "editor",
|
|
Short: "Open either the timer.txt file or the done.txt file in the default editor ",
|
|
RunE: opEditor,
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(editorCmd)
|
|
}
|
|
|
|
func opEditor(cmd *cobra.Command, args []string) error {
|
|
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()
|
|
}
|