Recently Written · git

ii-lchat-metapackage

Get suckless irc working for YOU

git clone https://github.com/equwal/ii-lchat-metapackage

Log | Files | Refs


irc-tail-f (985 bytes)

1 #!/bin/sh
2 # hint: make an alias wih the argument built-in for quickly deploying the tail -f script here
3 FILTER=.filter
4 IRCTOPLEVEL="$1"
5 LINES=${2:-5}
6 #cd "$1" ; tail -f -n $LINES $(find "$1" -name out | grep \#) | ./.filter
7 cd "$1"
8 # Create temp file for file list to avoid subshell
9 tempfile=$(mktemp)
10 
11 # Clean up all tail processes and temp file on exit/CTRL-C  
12 trap 'pkill -f "tail -F.*$1.*out"; rm -f "$tempfile"; exit' INT
13 
14 find "$1" -name out | grep "#" | sort > "$tempfile"
15 
16 while read file; do
17     channel=$(echo "$file" | sed 's/.*\/\(#[^\/]*\)\/out$/\1/')
18     # Generate color based on channel name hash using sum of all characters (mod to keep number small)
19     hash=$(printf "%s" "$channel" | od -b | awk '{for(i=2;i<=NF;i++) s=(s+$i)%1000} END{print s+0}')
20     color=$((31 + hash % 6))
21     (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) &
22 done < "$tempfile"
23 
24 rm "$tempfile"
25 wait