@@ 4,6 4,7 @@ import (
"fmt"
"log"
"os"
+ "os/exec"
"path/filepath"
"strings"
"time"
@@ 41,7 42,8 @@ var CLI struct {
Merge struct {
Path string `arg required type:"path" help:"path to a data file to merge with the default wt data file"`
} `cmd help:"merge an external wt data file"`
- DataFile string `optional short:"d" help:"path to the wt data file (default:$HOME/.local/wt.data)" type:"path"`
+ Edit struct{} `cmd help:"opens up the default editor for the wt data fiel"`
+ DataFile string `optional short:"d" help:"path to the wt data file (default:$HOME/.local/wt.data)" type:"path"`
InstallCompletions struct {
Uninstall bool
} `cmd help:"install shell completions"`
@@ 80,6 82,7 @@ func main() {
"merge": {
Args: predict.Files("*"),
},
+ "edit": {},
},
Flags: map[string]complete.Predictor{
"data-file": predict.Files("*"),
@@ 110,6 113,8 @@ func main() {
err = status()
case "merge <path>":
err = merge()
+ case "edit":
+ err = edit()
case "install-completions":
err = install.Install("wt")
default:
@@ 281,3 286,22 @@ func status() error {
)
return nil
}
+
+func edit() error {
+ if CLI.DataFile == "" {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return fmt.Errorf("getting user home dir: %w", err)
+ }
+ CLI.DataFile = filepath.Join(home, ".local", "wt.data")
+ }
+ editor := os.Getenv("EDITOR")
+ if editor == "" {
+ editor = "vim"
+ }
+ cmd := exec.Command(editor, CLI.DataFile)
+ cmd.Stdout = os.Stdout
+ cmd.Stdin = os.Stdin
+ cmd.Stderr = os.Stderr
+ return cmd.Run()
+}