dotfiles

$HOME is where the <3 is
git clone git://git.alexkarle.com/dotfiles.git
Log | Files | Refs | Submodules | README

commit ce99972a47cd00dcdd731f2ca999df62a89b1040 (patch)
parent 9f8d37dfb7b5c186f6c90a5e5365789448bd1bcb
Author: Alex Karle <alex@alexkarle.com>
Date:   Sat, 19 Jun 2021 23:54:07 -0400

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!

Diffstat:
Abin/irccolor | 44++++++++++++++++++++++++++++++++++++++++++++
Abin/irclogs | 18++++++++++++++++++
2 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/bin/irccolor 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 @@ -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