add an option to filter file content for preview

Mentioned in #5.
This commit is contained in:
Gokcehan committed 2016-08-28 15:04:57 +03:00
1 parent e86b8b34bd
commit c19d3450a2
4 files changed
+17 -3

No files matched your search

+13 -2
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"log"
"os"
"os/exec"
"path"
"sort"
"strconv"
@@ -255,9 +256,19 @@ func (win *Win) printr(reg *os.File) error {
return fmt.Errorf("printing regular file: %s", buf.Err())
}
reg.Seek(0, 0)
if len(gOpts.previewer) != 0 {
cmd := exec.Command(gOpts.previewer, reg.Name())
buf = bufio.NewScanner(reg)
out, err := cmd.Output()
if err != nil {
log.Printf("previewing file: %s", err)
}
buf = bufio.NewScanner(bytes.NewReader(out))
} else {
reg.Seek(0, 0)
buf = bufio.NewScanner(reg)
}
for i := 0; i < win.h && buf.Scan(); i++ {
win.print(2, i, fg, bg, buf.Text())