#!/usr/bin/perl -s

# color - output the input with the given color
# Steve Kinzler, steve@kinzler.com, Dec 13
# https://kinzler.com/me/home.html#unix

die "usage: $0 [ -f ] color [ patt ] [ cond ]\n" if $h;
($color, $patt, $cond) = @ARGV;

@in = <STDIN>;
exit		 unless @in;
print(@in), exit unless $f || -t 1;

use Term::ANSIColor;

foreach (@in) {
	print, next if $cond ne '' && ! eval $cond;
	s/$patt/color($color) . $& . color("reset")/ge,
		print, next if $patt ne '';
	s/\n?$/color('reset') . $&/e;	# color each line separately
	print color($color), $_;	#   for better `less -R` eg
}
