todo.shの補完

todo.txt が使えそうになってきたが,まともに使い始めると zsh の補完が欲しくなる.
ザッとググった限りではまだ無いみたいなので.自分で作る.
# ただし bash 版は本家で公開されている.

目標はコンテキスト名とかプロジェクト名が @ とか + の直後でタブを押すと補完されること.
つまり bash 版と同等くらいになればいいか.

以下のように記述された _todo.sh というファイルを $fpath という環境変数の通った場所に保存します.


#compdef todo.sh

local -a cmd
cmd=(add a append app archive del rm do list ls listall lsa listpri lsp)
cmd=($cmd prepend prep pri p replace remdup report)
_describe -t todo.sh-command "todo.sh command" cmd

_arguments -C -s \
'-d[Use a configuration file other than the default ~/.todo]:CONFIG_FILE:_files' \
'-f[Forces actions without confirmation or interactive input]' \
'-h[display help message]' \
'-p[Plain mode turns off colors]' \
'-v[Verbose mode turns on confirmation messages]' \
'-V[Displays version, license and credits]'

今日はここまで.

上記までで todo.sh と打った後にタブをするとサブコマンドとオプションが表示されます.