dotfiles

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

commit 69eb88690cbb651923da27521a3fd6fda5ddcddf (patch)
parent 0426040137a8f1b1868e152b76c9d8d9f5becc8d
Author: Alex Karle <alex@alexkarle.com>
Date:   Fri,  8 Oct 2021 22:06:11 -0400

irc: Add small scripts to improve sic(1) client

sic(1) is a dead simple IRC client that I like to leave open on the IRC
network I run as a way to make sure my bouncer isn't missing anything..

Also, I just generally enjoy programs that can be customized via shell
scripts, and `ic` does just that. It wraps sic(1) in a logger (tee(1)),
a colorizer (siccolor, standalone for log colorizing too), and rlwrap(1)
for improved UX.

Diffstat:
Abin/ic | 11+++++++++++
Abin/siccolor | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/bin/ic b/bin/ic @@ -0,0 +1,11 @@ +#!/bin/sh +# ic -- taking the simple out of sic(1) +set -e +mkdir -p "$HOME/.irc" +LOG="$HOME/.irc/$(date +%Y-%m-%d).log" + +if [ -z "$NOCOLOR" ]; then + rlwrap sic "$@" | tee -a "$LOG" | siccolor +else + rlwrap sic "$@" | tee -a "$LOG" +fi diff --git a/bin/siccolor b/bin/siccolor @@ -0,0 +1,51 @@ +#!/usr/bin/env perl +# siccolor -- colorize sic(1) output +use strict; +use warnings; +use Term::ANSIColor; + +# No black (bg), white (text/msg), bright white, or bright black (time) +my @colors = qw( + green + yellow + blue + magenta + cyan + bright_green + bright_yellow + bright_blue + bright_magenta + bright_cyan +); + +our $i = 0; +our %user_colors; +main(); + +sub main { + while (my $line = <>) { + if ($line =~ m{^([^:]+):\s+(\d\d\d\d-\d\d-\d\d \d\d:\d\d) (<[^>]+>)(.*)}) { + my ($channel, $time, $user, $msg) = ($1, $2, $3, $4); + print get_color($channel) . "$channel"; + print color("bright_black"); + print ": $time "; + print get_color($user) . "$user"; + print color("reset"); + print "$msg\n"; + } else { + # Don't know how to colorize! + print color("bright_black"); + print "$line"; + print color("reset"); + } + } +} + +sub get_color { + my ($val) = @_; + if (!exists $user_colors{$val}) { + $user_colors{$val} = $colors[$i % @colors]; + $i++; + } + return color($user_colors{$val}); +}