package editor import ( "os" "os/exec" "strings" ) const defaultEditor = "nano" // Cmd returns a *exec.Cmd editing the given path with $EDITOR or nano if no // $EDITOR is set. func Cmd(path string) *exec.Cmd { editor, args := getEditor() return exec.Command(editor, append(args, path)...) } func getEditor() (string, []string) { editor := strings.Fields(os.Getenv("EDITOR")) if len(editor) > 1 { return editor[0], editor[1:] } if len(editor) == 1 { return editor[0], []string{} } return defaultEditor, []string{} }