Zsh completion for home grown scripts

I use irssi on a cloud server for my IRC needs. Along with it I’ve written some utility scripts - the most useful is kibo to find all messages sent to myself by searching the irssi logs.

Since my home dir is a bit longer lived my scripts keep getting little tweaks and improvements. One I’ve been doing lately is completions. I had hoped yesterday to show a more complicated zsh completion example but so far haven’t gotten it to work.

So instead I’ll show one in progress. I know I’ve likely done the _list functions wrong as well as the last two args to _regex_words but not fully clear how I’m supposed to do it. For some reason I find completion docs (for tcsh, bash and zsh) hard to read. No idea why. Any tips welcome!

‘kibo’ completion script:

#compdef kibo

local -a reply nick channel

_nick_list() {
  local -a nicks
  nicks=($(find ~/.irssi/log/* -name '[a-zA-Z0-9]*.log' |
           sed 's@.*/@@;s/.log//' | sort -u))
  _describe -t nick-list nickname nicks "$@"
}

nick=(
  /$'[^\0]#\0'/ ':nick-list:nickname:_nick_list'
)

_channel_list() {
  local -a channels
  channels=($(find ~/.irssi/log/* -name '#*.log' |
              sed 's/.*#//;s/.log//' | sort -u))
  _describe -t channel-list 'channel name' channels "$@"
}

channel=(
  /$'[^\0]#\0'/ ':channel-list:channel name:_channel_list'
)

_regex_words \
  commands "kibo flags" \
  '-h:help' \
  '-c:add context' \
  '@*:search for nick:$nick' \
  '#*:search channel:$channel'

echo "Loading: ${reply[*]}"
_regex_arguments _kibo_util "${reply[@]}"

_kibo() {
  echo "hi: '$*'"
  _kibo_util "$@"
}

_kibo "$@"

kibo:

#!/bin/bash

file=~/.irssi/log/ilug/\#linux.log
lines=-10
pat=$USER

for arg in "$@"; do
  case "$arg" in
    -h|--help)
      cat $HOME/bin/kibo
      exit
      ;;
    -c)
      grepargs="-C 3"
      ;;
    -*)
      lines="$arg"
      ;;
    @*|/*)
      pat="${arg#[@/]}"
      ;;
    \#*)
      file=~/.irssi/log/*/${arg}.log
      ;;
    *)
      file=~/.irssi/log/*/*${arg}*.log
      ;;
  esac
done

egrep -a $grepargs "$pat" $file | tail $lines