3 ms·
I mostly run into this on searching my environment: "set | grep whatever", now needs an "-a", possibly because of escape codes added to the environment a decade
by linsomniac 7y ago
I mostly run into this on searching my environment: "set | grep whatever", now needs an "-a", possibly because of escape codes added to the environment a decade ago.
Maybe the fix would be to only activate the "detect binary files" code if stdout isatty?
Because it is a nice feature when I do a big grep to find something among my home directory or the entire filesystem. It is certainly annoying to get binary garbage in my terminal. Or maybe the binary detection could get smarter, maybe making the determination on a match-by-match basis ("This line I'm about to output is a kilobyte and half of it is non-printable", say).
Though, ack-grep doesn't seem to avoid putting binary garbage on my terminal, so maybe reasonable to switch to something that isn't so clever? Most of my terminal greping is done with ack these days, so I'd probably be happy with gnu-grep disabling this cleverness.
- downerending 7y agoUsually you want this feature no matter where the output is going. Adding "-a" sucks, but it's not obvious how else this could work (and still be backward-compatible). IIRC the grep heuristic only considers a short prefix of the file. If the garbage comes later, you lose. Unfortunately, this makes things seem a bit unpredictable.
- linsomniac 7y agoI probably do not want this feature the case of a script, as this post talks about. Which is why I was suggesting if isatty(stdout). Most people do not want their shell scripts functionality to depend on whether there is a "high character" somewhere in it.
- gumby 7y ago> IIRC the grep heuristic only considers a short prefix of the file. If the garbage comes later, you lose. Unfortunately, this makes things seem a bit unpredictable. This was changed about five years ago to just keep looking. Which makes things a bit unpredictable in a different way.