1 # nmh completion for bash
2 # Copyright 2003 "Wade Richards" <wade@wabyn.net>
3 # Permission granted to redistribute under the BSD license
8 # args: command comp-word prev-word
9 local command current prev folder origfolder i orig_opts
12 current=${COMP_WORDS[COMP_CWORD]}
13 prev=${COMP_WORDS[COMP_CWORD-1]}
16 orig_opts=$(shopt -p extglob)
19 # Get the folder, if specified
20 for (( i=0; i < ${#COMP_WORDS}-1; i++ ))
22 case "${COMP_WORDS[i]}" in
24 folder=${COMP_WORDS[i]}
25 origfolder=$( folder -f )
32 # Command-line switches for the most common commands.
35 # no sequences or messages
36 options=(-alias -list -nolist -normalize -nonormalize -user
37 -nouser -version -help)
40 options=(-inplace -noinplace -quiet -noquiet -verbose
41 -noverbose -version -help)
44 options=(-form -use -nouse -file -draftfolder -draftmessage
45 -nodraftfolder -editor -noedit -whatnowproc -nowhatnowproc
49 options=(-sequence -all -noall -showzero -noshowzero
50 -recurse -norecurse -fast -nofast -alpha -noalpha -version
54 options=(-all -noall -create -nocreate -fast -nofast -header
55 -noheader -recurse -norecurse -total -nototal -list -nolist
56 -push -pop -pack -nopack -print -verbose -noverbose -version
60 options=(-annotate -noannotate -form -format -noformat
61 -filter -inplace -noinplace -mime -nomime -draftfolder
62 -draftmessage -nodraftfolder -editor -noedit -whatnowproc
63 -nowhatnowproc -dashstuffing -nodashstuffing -build -file
67 options=(-audit -noaudit -changecur -nochangecur -form -format
68 -file -silent -nosilent -truncate -notruncate -width -host
69 -user -pack -nopack -apop -noapop -kpop -sasl -saslmech -snoop
73 options=(-sequence -add -delete -list -public -nopublic
74 -zero -nozero -version -help)
77 options=(-showmimeproc -header -noheader -checkmime
78 -nocheckmime -version -help)
81 options=(-file -mbox -mmdf -version -help)
84 options=(-and -or -not -lbrace -rbrace --component -cc
85 -date -from -search -subject -to -after -before -datefield
86 -sequence -public -nopublic -zero -nozero -list -nolist
90 options=(-showproc -showmimeproc -header -noheader -checkmime
91 -nocheckmime -version -help)
94 options=(-draft -link -nolink -preserve -nopreserve -unlink
95 -nounlink -src -file -rmmproc -normmproc -version -help)
98 options=(-annotate -noannotate -group -nogroup -cc
99 -nocc -query -noquery -form -format -noformat -filter
100 -inplace -noinplace -mime -nomime -fcc -width -draftfolder
101 -draftmessage -nodraftfolder -editor -noedit -whatnowproc
102 -nowhatnowproc -build -file -version -help)
105 options=(-interactive -nointeractive -version -help)
108 options=(-link -nolink -version -help)
111 options=(-clear -noclear -form -format -header -noheader
112 -width -reverse -noreverse -file -version -help )
115 options=(-draft -showproc -showmimeproc -header -noheader
116 -checkmime -nocheckmime -version -help)
119 options=(-datefield -textfield -notextfield -limit -nolimit
120 -verbose -noverbose -version -help)
123 options=(-alias -check -nocheck -draft -draftfolder
124 -draftmessage -nodraftfolder -version -help)
127 options=(-help -version -seq)
134 options=( $( folder -all -r -fast | grep -v "^\." | sed "s/^/+/" ) )
139 start=${current/%-*/}
140 options=( $( scan $folder -format "%(msg)" "${start}-last" ) first prev cur next last )
141 options=( ${options[@]//#/${start}-} )
145 # Message number, or start of range
146 options=( $( scan $folder -format "%(msg)" ) first prev cur next last )
147 options=( ${options[@]} ${options[@]//%/-} )
151 # special message aliases
152 options=( first prev cur next last unseen )
155 # What about sequences? I can't quite see how to get the list of possible sequences, so I
156 # guess the user will have to type them in the old-fashioned way.
162 COMPREPLY=( $( compgen -W "${options[*]}" -- $current ) )
165 [ "$have" ] && complete -F _nmh ali anno burst comp dist flist flists folder folders forw inc mark mhbuild mhl mhlist mhmail mhn mhparam mhpath mhshow mhstore msgchk msh next packf pick prev prompter rcvdist rcvpack rcvstore rcvtty refile repl rmf rmm scan send sendfiles show slocal sortm whatnow whom