~porcellis/t

31612889bc86fff7e03829fe6fa39cda919dc79a — Pedro Lucas Porcellis 1 year, 2 months ago 75ab537
Use glow to display notes
2 files changed, 37 insertions(+), 0 deletions(-)

A commands/show.go
M main.go
A commands/show.go => commands/show.go +17 -0
@@ 0,0 1,17 @@
package commands

import (
	"git.sr.ht/~porcellis/t/models"
	"os"
	"os/exec"
)

func Show(note models.Note) error {
	// TODO: Make this configurable
	cmd := exec.Command("glow", note.Path, "-p")
	cmd.Stdin = nil
	cmd.Stdout = os.NewFile(0, os.DevNull)
	cmd.Stderr = os.Stderr

	return cmd.Run()
}

M main.go => main.go +20 -0
@@ 99,6 99,26 @@ func main() {

		println("Finished editing ", note.Title())

	case "show", "s":
		var note models.Note
		notes, _ := commands.BuildList(*configuration)

		if len(os.Args) == 2 {
			note = notes[0]
		} else {
			index, err := strconv.Atoi(os.Args[2])

			if err == nil {
				note = notes[index]
			}
		}

		err = commands.Show(note)

		if err != nil {
			panic("There was some error when trying to display the note")
		}

	case "version", "v":
		println("t ", Version)