t

commit 31612889bc86fff7e03829fe6fa39cda919dc79a

Author: Pedro Lucas Porcellis <pedrolucasporcellis@gmail.com>

Use glow to display notes

 commands/show.go | 17 +++++++++++++++++
 main.go | 20 ++++++++++++++++++++


diff --git a/commands/show.go b/commands/show.go
new file mode 100644
index 0000000000000000000000000000000000000000..5c72bac500a7776c08945138322cdc21f1b6329d
--- /dev/null
+++ b/commands/show.go
@@ -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()
+}




diff --git a/main.go b/main.go
index c338bfd7b3ddd067094f334cc46d507b39a9dab1..8ad0c392fb0c4f02994c3d8eb4e910c828aa7618 100644
--- a/main.go
+++ b/main.go
@@ -99,6 +99,26 @@ 		}
 
 		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)