# vim:et sts=2 sw=2 ft=zsh
builtin emulate -L zsh

if (( # < 1 )); then
  print -u2 "usage: ${0} <path to git module> [pattern...]"
  return 2
fi
local gprefix
zstyle -s ':zim:git' aliases-prefix 'gprefix' || gprefix=G

local gline galias
local -r gmodule_home=${1}
shift
local -r gpattern=${(j:.*:)@}
# read one-line documentations from README.md
while IFS= read -r gline; do
  if [[ ${gline} =~ '^ *\* `G([^`]*)` (.*)$' ]]; then
    galias=${gprefix}${match[1]}
    gline=${galias}$'\t'${aliases[${galias}]}$'\t'${match[2]}
    if [[ -z ${gpattern} || ${gline} =~ ${gpattern} ]] print -R ${gline}
  fi
done < ${gmodule_home}/README.md | command column -s $'\t' -t
