# 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
      ali) switches=(-help -version -alias -list -nolist -user -nouser) ;;
      anno) switches=(-help -version -component -inplace -noinplace -date -nodate -draft -append -list -delete -number -preserve -nopreserve -text) ;;
      ap) switches=(-help -version -form -format -width) ;;
      burst) switches=(-help -version -inplace -noinplace -mime -nomime -automime -quiet -noquiet -verbose -noverbose) ;;
      comp) switches=(-help -version -form -use -nouse -file -draftfolder -draftmessage -nodraftfolder -editor -noedit -width -from -to -cc -fcc -subject -whatnowproc -nowhatnowproc -build) ;;
      dist) switches=(-help -version -form -annotate -noannotate -inplace -noinplace -draftfolder -draftmessage -nodraftfolder -editor -noedit -width -from -to -cc -fcc -whatnowproc -nowhatnowproc -atfile -noatfile) ;;
      dp) switches=(-help -version -form -format -width) ;;
      flist) switches=(-help -version -sequence -sequence -all -noall -showzero -noshowzero -recurse -norecurse -fast -nofast -alpha -noalpha) ;;
      flists) switches=() ;;
      flist) switches=(-help -version -sequence -sequence -all -noall -showzero -noshowzero -recurse -norecurse -fast -nofast -alpha -noalpha) ;;
      fmtdump) switches=(-help -version -form -format) ;;
      fmttest) switches=(-help -version -form -format -address -raw -date -message -file -nofile -component -dupaddrs -nodupaddrs -ccme -noccme -outsize -width -msgnum -msgcur -msgsize -unseen -dump -nodump -trace -notrace) ;;
      folder) switches=(-help -version -all -noall -create -nocreate -fast -nofast -header -noheader -recurse -norecurse -total -nototal -list -nolist -push -pop -pack -nopack -print -noprint -verbose -noverbose) ;;
      folders) switches=() ;;
      folder) switches=(-help -version -all -noall -create -nocreate -fast -nofast -header -noheader -recurse -norecurse -total -nototal -list -nolist -push -pop -pack -nopack -print -noprint -verbose -noverbose) ;;
      forw) switches=(-help -version -annotate -noannotate -form -format -noformat -filter -inplace -noinplace -mime -nomime -draftfolder -draftmessage -nodraftfolder -editor -noedit -width -from -to -cc -fcc -subject -whatnowproc -nowhatnowproc -dashstuffing -nodashstuffing -build -file -help -version -digest -issue -volume) ;;
      forw) switches=(-help -version -annotate -noannotate -form -format -noformat -filter -inplace -noinplace -mime -nomime -draftfolder -draftmessage -nodraftfolder -editor -noedit -width -from -to -cc -fcc -subject -whatnowproc -nowhatnowproc -dashstuffing -nodashstuffing -build -file -help -version -digest -issue -volume) ;;
      inc) switches=(-help -version -audit -noaudit -changecur -nochangecur -form -format -file -silent -nosilent -truncate -notruncate -width -host -port -user -proxy -sasl -nosasl -saslmech -authservice -tls -initialtls -notls -certverify -nocertverify -snoop) ;;
      install\-mh) switches=() ;;
      mark) switches=(-help -version -sequence -add -delete -list -public -nopublic -zero -nozero -empty -noempty -range -norange) ;;
      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 ali anno ap burst comp dist dp flist flists flist fmtdump fmttest folder folders folder forw forw inc install\-mh mark mime
