# ih completion

_get_pos() {
  ih $1 --help | egrep -o '^[ ]+[a-z]+' | xargs
}

_get_opt() {
  ih $1 --help | egrep -o ' \-[a-z]+' | xargs
}

_ih() 
{
  COMPREPLY=()
  cur="${COMP_WORDS[COMP_CWORD]}"
  _subcommands="$(_get_opt) "
  _subcommands+="$(_get_pos)"

  if [[ ${COMP_CWORD} == 1 ]]; then
    COMPREPLY=( $(compgen -W "${_subcommands}" -- ${cur}) )
    return 0 
  fi

  subcmd_1="${COMP_WORDS[1]}"
  case "${subcmd_1}" in
    *)
      _subcommands="$(_get_opt $subcmd_1) "
      _subcommands+=`ls /place/db/iss3/instances/`
      COMPREPLY=($(compgen -W "${_subcommands}" -- ${cur}))
      return 0
      ;;
  esac

}
complete -F _ih ih
