Mercurial > hg > Members > anatofuz > growsync
view editor.go @ 15:0dc44ee170b4
mkdir
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 03 Jan 2021 08:46:08 +0900 |
parents | c775cee5aac2 |
children |
line wrap: on
line source
package growsync import ( "os" "os/exec" "strings" "github.com/mattn/go-tty" "golang.org/x/xerrors" ) func doEdit(mdfilePATH string) error { editor := os.Getenv("EDITOR") if editor == "" { editor = "vi" } tty, err := tty.Open() if err != nil { return xerrors.Errorf("[error] failed open tty %+w", err) } defer tty.Close() editorWithArgs := strings.Fields(editor) editorWithArgs = append(editorWithArgs, mdfilePATH) cmd := exec.Command(editorWithArgs[0], editorWithArgs[1:]...) cmd.Stdin = tty.Input() cmd.Stdout = tty.Output() cmd.Stderr = tty.Output() if err := cmd.Run(); err != nil { return xerrors.Errorf("[error] failed exec editor %+w", err) } return nil }