# nmh completion for bash
# Copyright 2003 "Wade Richards" <wade@wabyn.net>
# Permission granted to redistribute under the BSD license

if ! type _nmh &>/dev/null ; then
    _nmh()
    {
        # args: command comp-word prev-word
        local command current prev folder origfolder i orig_opts

        COMPREPLY=()
        current=${COMP_WORDS[COMP_CWORD]}
        prev=${COMP_WORDS[COMP_CWORD-1]}
        command=$1

        orig_opts=$(shopt -p extglob)
        shopt -s extglob

        # Get the folder, if specified
        for (( i=0; i < ${#COMP_WORDS}-1; i++ ))
        do
            case "${COMP_WORDS[i]}" in
            \++([a-zA-Z_]) )
                folder=${COMP_WORDS[i]}
                origfolder=$( folder -f )
                ;;
            esac
        done

        case $current in
        -* )
            # Command-line switches for the most common commands.
            case $command in
            ali )
                # no sequences or messages
                options=(-alias -list -nolist -normalize -nonormalize -user
                        -nouser -Version -help)
                ;;
            burst )
                options=(-inplace -noinplace -quiet -noquiet -verbose
                        -noverbose -Version -help)
                ;;
            comp )
                options=(-form -use -nouse
                        -editor -noedit -whatnowproc
                        -Version -help )
               ;;
            flist* )
                options=(-sequence -all -noall -showzero -noshowzero
                        -recurse -norecurse -fast -nofast -alpha -noalpha -Version
                        -help)
                ;;
            folder* )
                options=(-all -noall -create -nocreate -fast -nofast -header
                        -noheader -recurse -norecurse -total -nototal -list -nolist
                        -push -pop -pack -nopack -print -verbose -noverbose
                        -Version -help)
                ;;
            forw )
                options=(-annotate -noannotate -form
                        -editor -noedit -whatnowproc -build
                        -Version -help)
                ;;
            inc )
                options=(-audit -noaudit -changecur -nochangecur -form
                        -file -silent -nosilent -truncate -notruncate -width
                        -Version -help)
                ;;
            mark )
                options=(-sequence -add -delete -list -public -nopublic
                        -zero -nozero -Version -help)
                ;;
            packf )
                options=(-file -Version -help)
                ;;
            pick )
                options=(-and -or -not -lbrace -rbrace --component -cc
                        -date -from -search -subject -to -after -before -datefield
                        -sequence -public -nopublic -zero -nozero -list -nolist
                        -Version -help)
                ;;
            refile )
                options=(-link -nolink -src -file -Version -help)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           