# bash completions for nmh commands                        -*- shell-script -*-
# This file was generated by etc/bash_completion_nmh-gen.
#
# This code is Copyright (c) 2016, by the authors of nmh.
# See the COPYRIGHT file in the root directory of the nmh
# distribution for complete copyright information.
#
# To use:  source at a bash prompt or in an initialization file.

_nmh() {
  local -a switches

  COMPREPLY=()
  #### Complete filenames.
  compopt -o default

  case ${COMP_WORDS[COMP_CWORD]} in
  -*) case $1 in
      esac ;;

  +*) switches=($(folder -all -fast -recurse | sed 's/^/+/')) ;;

  #### Complete special message names, except after -file.  The compopt -o default above provides filename completions.  Assume that -file was fully completed, so don't need to match -fil, etc.
  [flc.np]*) [ ${COMP_CWORD:-0} -lt 2  -o  ${COMP_WORDS[$(($COMP_CWORD - 1))]} != -file ]  &&
                 switches=(first last cur . next prev) ;;
  esac

  #### Special case:  add "new" to mhpath's completions.
  [ $1 = mhpath ]  &&  switches=("${switches[*]}" + new)

  COMPREPLY=($(compgen -W "${switches[*]}" -- ${COMP_WORDS[COMP_CWORD]}))
}

complete -F _nmh mime
