Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func main() {
var dumpMode bool
flag.BoolVar(&dumpMode, "dump", false, "prints the grep command rather than executing it")

var colorMode bool
flag.BoolVar(&colorMode, "color", false, "display color-highlighting the matches in output")

flag.Parse()

if listMode {
Expand Down Expand Up @@ -98,15 +101,22 @@ func main() {

} else {
var cmd *exec.Cmd
colorVal := "--color="
operator := "grep"
if pat.Engine != "" {
operator = pat.Engine
}

if colorMode {
colorVal += "always"
} else {
colorVal += "never"
}

if stdinIsPipe() {
cmd = exec.Command(operator, pat.Flags, pat.Pattern)
cmd = exec.Command(operator, pat.Flags, pat.Pattern, colorVal)
} else {
cmd = exec.Command(operator, pat.Flags, pat.Pattern, files)
cmd = exec.Command(operator, pat.Flags, pat.Pattern, colorVal, files)
}
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
Expand Down