Permalink
Browse files

camptail: add --grep option

This can be used to grep for a pattern in the tail content,
like:

  camptail --no-follow --grep=peff -r 'The Danger Room' -t 1000

Note that the pattern is case-insensitive for convenience.
  • Loading branch information...
peff committed Feb 16, 2011
1 parent 8a85514 commit 8cb575e55ae8460b6777411f9eb48577743c6d53
Showing with 16 additions and 0 deletions.
  1. +16 −0 camptail.pl
View
@@ -25,6 +25,7 @@
't|tail=i' => \$tail,
'callback=s' => \&setup_callback,
'print' => sub { $callback = \&print_message },
'grep=s' => \&setup_grep,
'v|verbose!' => \$verbose,
'r|room=s' => \@want_rooms_commandline,
'f|follow!' => \$follow,
@@ -93,3 +94,18 @@ sub setup_callback {
EOF
$@ and die $@;
}
{
my $re;
sub setup_grep {
my (undef, $pattern) = @_;
$re = qr/$pattern/i;
$callback = \&grep_message;
}
sub grep_message {
my ($message, $room) = @_;
print_message(@_) if $message->body =~ $re;
}
}

0 comments on commit 8cb575e

Please sign in to comment.