Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Last active February 26, 2026 20:44
Show Gist options
  • Select an option

  • Save ormaaj/7220920d4d78926c2dae02e5c5bc7354 to your computer and use it in GitHub Desktop.

Select an option

Save ormaaj/7220920d4d78926c2dae02e5c5bc7354 to your computer and use it in GitHub Desktop.
weechat log stats analyzer
#!/usr/bin/env ksh
function chanStats {
nameref ret=$1
typeset -T ChanStats=(
logdir=~/.weechat/logs
typeset logfile channel network
typeset -a stats
function generateStats {
typeset x name IFS=$' \t'
integer -A a
ansifilter -i "${_.logfile}" |
while read -r x x name x; do
[[ $name == ~(P)^(?:<--(?!>)|(?<!<)-->|\*+|--|=!=)$ ]] || (( ++a[${name##[@+]}] ))
done
for x in "${!a[@]}"; do
_.stats[${a[$x]}]+=("$x")
done
}
function init {
echo "$network"
_.logfile=${_.logdir}/irc.${_.network}.${_.channel}.weechatlog
if [[ ! -f ${_.logfile} ]]; then
printf $'Error: logfile doesn\'t exist: %q\\n' "${_.logfile}" >&2
return 1
fi
_.generateStats
}
)
ChanStats o=(network=$2 channel=$3)
o.init || return
typeset -m ret=o
}
function main {
typeset cs
chanStats cs "${1:-libera}" "${2:-#bash}" || return
print -C cs.stats
}
main "$@"
# vim: set ft=bash fenc=utf-8 ff=unix ts=4 sw=4 noet :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment