rijiの zsh補完

空前のRijiブームに乗り遅れるな!(棒) | おそらくはそれさえも平凡な日々


空前のブームなので, zsh補完を書いてみました.

コード

#compdef riji

typeset -A opt_args
local context state line

local -a _riji_subcommands
_riji_subcommands=(
  "new-entry:create Today's new entry"
  "setup:setup riji"
  "publish:publish blog entries"
  "help:display a command's help screen"
)

_arguments '*:: :->subcmd'

if [[ "$state" == "subcmd" ]];then

  if (( CURRENT == 1)); then
    _describe -t commands "riji command" _riji_subcommands -V1
    return
  else
    local opts curcontext

    case "$words[1]" in
      setup)
        opts=(
          '(--force)--force[Force setup riji]'
        )
        ;;
      *)
        opts=()
        ;;
    esac
    _arguments -s : "$opts[@]" '*::Files:_files'
  fi
fi

# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et

イメージ

setupのときは, --forceオプションも補完してくれます

おわりに

問題があればお知らせください.