From 1e61bd07cfdb13174f6bc2ac77b704edd5d5d292 Mon Sep 17 00:00:00 2001 From: BuffaloWill Date: Thu, 19 Sep 2019 08:35:55 -0400 Subject: [PATCH] Added stream mode --- main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.go b/main.go index 5fb6a74..2e37f29 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,9 @@ func main() { var dumpMode bool flag.BoolVar(&dumpMode, "dump", false, "prints the grep command rather than executing it") + var streamMode bool + flag.BoolVar(&streamMode, "stream", false, "sets gf in stream mode") + flag.Parse() if listMode { @@ -92,6 +95,12 @@ func main() { pat.Pattern = "(" + strings.Join(pat.Patterns, "|") + ")" } + if streamMode { + // for stream mode, remove the recursive flag ("r") and filename ("H") which is always stdin + pat.Flags = strings.Replace(pat.Flags,"r","", -1) + pat.Flags = strings.Replace(pat.Flags,"H","", -1) + } + if dumpMode { fmt.Printf( "grep --color %v %q %v\n", pat.Flags, pat.Pattern, files ) //fmt.Println( "grep --color", pat.Flags, pat.Pattern, files)