Created
July 29, 2011 15:42
-
-
Save hideo55/1114069 to your computer and use it in GitHub Desktop.
keyword coloring on terminal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl -w | |
use strict; | |
my $kw_path = shift @ARGV; | |
if( !defined($kw_path) || !(-e $kw_path ) ){ | |
die <<"__USAGE__"; | |
Usage: | |
# tail -f | ./color.pl keywords.pl | |
keywords are defined by ArrayRef such as: | |
[qw(error fail)]; | |
__USAGE__ | |
} | |
my $keywords = do $kw_path; | |
die "Keywords must be ARRAY reference." if !defined $keywords || ( ref($keywords) || q{} ) ne 'ARRAY'; | |
die "You must define keywords one or more" if @$keywords == 0; | |
my $pattern = join '|', map{ qq{\Q$_\E} } @$keywords; | |
$pattern = qr/($pattern)/i; | |
while(<STDIN>){ | |
s/$pattern/\x1b[31m$1\x1b[0m/g;#red | |
print; | |
} | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment