if [[ ! -o interactive ]]; then
    return
fi

compctl -K _hr hr

_hr() {
  local word words completions
  read -cA words
  word="${words[2]}"

  if [ "${#words}" -eq 2 ]; then
    completions="$(hr commands)"
  else
    completions="$(hr completions "${word}" ${words[@]:2})"
  fi

  reply=("${(ps:\n:)completions}")
}

_hr_commands() {
  local cmds
  local -a commands
  cmds="$(hr commands)"
  commands=(${(ps:\n:)cmds})
  _wanted command expl "hr command" compadd -a commands
}

_hr_subcommands() {
  local cmd subcmds
  local -a commands
  cmd="${words[2]}"
  subcmds="$(hr completions ${words[2,$(($CURRENT - 1))]})"
  commands=(${(ps:\n:)subcmds})
  _wanted subcommand expl "hr $cmd subcommand" compadd -a commands
}

_hr() {
  case $CURRENT in
    2) _hr_commands ;;
    *) _hr_subcommands ;;
  esac
}

compdef _hr hr

Use the newer zsh completion engine
Use the newer zsh completion engine
