Zsh completion for home grown scripts (part 2)

When last we checked, our intrepid lazy typer was trying to write a completion rule for kibo to reduce his keystrokes a microscopic ammount.

The working ‘kibo’ completion script:

#compdef kibo

_whowhere() {
  local -a nicks channels
  nicks=($(find ~/.irssi/log/* -name '[a-zA-Z0-9]*.log' -size +500c |
           sed 'sX.*/X@X;s/.log//' | grep -v '[_|!]' | sort -u))
  channels=($(find ~/.irssi/log/* -name '#*.log' -size +500c |
              sed 's/.*#/#/;s/.log//' | grep -v '[_|!]' | sort -u))
  _values "Who and where to find" "${nicks[@]}" "${channels[@]}"
}

_kibo() {
  _alternative \
    'args:custom arg:((-h\:"help" -c\:"add context"))' \
    'whowhere:Who and where to find:_whowhere'

}

_kibo "$@"

Amusingly it’s way, way shorter than the one that didn’t work. Not an uncommon occurance really.

The key issue was that I kept thinking of # and @ as “flag markers” like -. But it was just easier to treat them as _values with my custom flag characters prepended.