phコマンドの zsh補完を書きました

https://metacpan.org/module/App::ph


Perlでできた hubコマンドのようなものです。

コード

#compdef ph

typeset -A opt_args
local context state line

local -a _ph_subcommands
_ph_subcommands=(
  'import:Import current directory to github'
  'clone:Clone repository'
  'fork:Fork the repository to my github account'
  'pull:Fetch remote changes'
  'pullreq:Pull request'
  'add:Add remote reposity and fetch'
  'info:Display information of repository'
  'all:Clone all repository in my account'
  'issues:Show list of current project'
  'help:Show this message'
)

_arguments '*:: :->subcmd'

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

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

    case "$words[1]" in
      clone)
        opts=('--fork[fork repository]')
        ;;
      import)
        opts=(
          '--remote=[Remote repository]'
          '--homepage=[Repository homepage]'
          '--description=[Repositry description]'
          '--private[Import as private]'
        )
        ;;
      *)
        opts=()
        ;;
    esac
    _arguments -n : "$opts[@]" '*: :()'
  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

イメージ

サブコマンドの補完

サブコマンドオプションの補完