commit 6244a743a17bb5e92f68c9783d59ec9222198534 Spenser Truex <truex@equwal.com> 2025-09-03 12:14:14 -0700 Add IRC tail watcher with fancy colors The colors are based on the channel name's hash, so they get a "random" but always the same hash. Very nice!
irc-tail-f | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/irc-tail-f b/irc-tail-f index 8094349..4848b53 100755 --- a/irc-tail-f +++ b/irc-tail-f @@ -1,4 +1,25 @@ #!/bin/sh # hint: make an alias wih the argument built-in for quickly deploying the tail -f script here +FILTER=.filter IRCTOPLEVEL="$1" -cd "$1" ; tail -f -n 5 $(find "$1" -name out | grep \#) | ./.filter +LINES=${2:-5} +#cd "$1" ; tail -f -n $LINES $(find "$1" -name out | grep \#) | ./.filter +cd "$1" +# Create temp file for file list to avoid subshell +tempfile=$(mktemp) + +# Clean up all tail processes and temp file on exit/CTRL-C +trap 'pkill -f "tail -F.*$1.*out"; rm -f "$tempfile"; exit' INT + +find "$1" -name out | grep "#" | sort > "$tempfile" + +while read file; do + channel=$(echo "$file" | sed 's/.*\/\(#[^\/]*\)\/out$/\1/') + # Generate color based on channel name hash using sum of all characters (mod to keep number small) + hash=$(printf "%s" "$channel" | od -An -tu1 | tr -d ' ' | awk '{s=0; for(i=1;i<=NF;i++) s=(s+$i)%1000; print s}') + color=$((31 + hash % 6)) + (tail -F -n $LINES "$file" | ./"$FILTER" | sed -u 's/\x1b\[[0-9;]*m//g' | sed -u "s/^/\x1b[${color}m[$channel]\x1b[0m\t/" | stdbuf -o0 cat) & +done < "$tempfile" + +rm "$tempfile" +wait