From ce99972a47cd00dcdd731f2ca999df62a89b1040 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Sat, 19 Jun 2021 23:54:07 -0400 Subject: [PATCH] irc: Add two custom scripts to go through my logs The more time spent improving my irc setup, the more I love it. I mean, getting to use grep + perl to dig through and colorize my logs? How cool is that? Slack aint got nothing on grep for searching :) These two scripts work in tandem to go through my soju logs: $ irclogs soju | irccolor | less -R Pretty cool! --- bin/irccolor | 44 ++++++++++++++++++++++++++++++++++++++++++++ bin/irclogs | 18 ++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100755 bin/irccolor create mode 100755 bin/irclogs diff --git a/bin/irccolor b/bin/irccolor new file mode 100755 index 0000000..79a1cab --- /dev/null +++ b/bin/irccolor @@ -0,0 +1,44 @@ +#!/usr/bin/env perl +# irccolor -- filter to colorize the output of irclogs +# usage: irclogs sr.ht | irccolor | less -R +use strict; +use warnings; +use Term::ANSIColor; + +# No black (bg), white (text/msg), bright white, or bright black (time) +my @colors = qw( + red + green + yellow + blue + magenta + cyan + bright_red + bright_green + bright_yellow + bright_blue + bright_magenta + bright_cyan +); + +my $i = 0; +my %user_colors; +while (my $line = <>) { + if ($line =~ m{(\d\d\d\d-\d\d-\d\d).log:\[(\d\d:\d\d:\d\d)]\s*(<[^>]+>)(.*)}) { + my ($date, $time, $user, $msg) = ($1, $2, $3, $4); + print color("bright_black"); + print "[$date $time] "; + print color("reset"); + if (!exists $user_colors{$user}) { + $user_colors{$user} = $colors[$i % @colors]; + $i++; + } + print color("$user_colors{$user}"); + print $user; + print color("reset"); + print "$msg\n"; + } else { + # Don't know how to colorize! + print "$line"; + } +} diff --git a/bin/irclogs b/bin/irclogs new file mode 100755 index 0000000..02a48a9 --- /dev/null +++ b/bin/irclogs @@ -0,0 +1,18 @@ +#!/bin/sh +# irclogs -- small script to get only the messages from logs +set -e +die() { + echo "$*" 1>&2 + exit 1 +} + +LOGS=/home/_soju/logs + +[ -z "$1" ] && die "usage: $0 CHANNEL" +[ ! -d "$LOGS/$USER" ] && die "User $USER doesn't appear to have a soju account" +[ ! -d "$LOGS/$USER/irc.libera.chat/#$1" ] && die "channel #$1 doesn't have any logs" + +# cd into the log dir as a cheap way to truncate output +cd "$LOGS/$USER/irc.libera.chat/#$1" + +grep '^\[[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\] *<' *.log -- libgit2 0.28.4