f759c3577c2dd2a4dd51ca5a55a2091dcc60a28d
[mmh] / docs / COMPLETION-BASH
1 # nmh completion for bash
2 # Copyright 2003 "Wade Richards" <wade@wabyn.net>
3 # Permission granted to redistribute under the BSD license
4
5 have show &&
6 _nmh()
7 {
8     # args: command comp-word prev-word
9     local command current prev folder origfolder i orig_opts
10
11     COMPREPLY=()
12     current=${COMP_WORDS[COMP_CWORD]}
13     prev=${COMP_WORDS[COMP_CWORD-1]}
14     command=$1
15
16     orig_opts=$(shopt -p extglob) 
17     shopt -s extglob
18
19     # Get the folder, if specified
20     for (( i=0; i < ${#COMP_WORDS}-1; i++ ))
21     do
22         case "${COMP_WORDS[i]}" in
23         \++([a-zA-Z_]) )
24             folder=${COMP_WORDS[i]} 
25             origfolder=$( folder -f )
26             ;;
27         esac
28     done
29
30     case $current in 
31     -* ) 
32         # Command-line switches for the most common commands.
33         case $command in
34         ali ) 
35             # no sequences or messages
36             options=(-alias -list -nolist -normalize -nonormalize -user
37                     -nouser -version -help)
38             ;;
39         burst ) 
40             options=(-inplace -noinplace -quiet -noquiet -verbose
41                     -noverbose -version -help)
42             ;;
43         comp )
44             options=(-form -use -nouse -file -draftfolder -draftmessage
45                     -nodraftfolder -editor -noedit -whatnowproc -nowhatnowproc
46                     -version -help )
47            ;; 
48         flist* )
49             options=(-sequence -all -noall -showzero -noshowzero
50                     -recurse -norecurse -fast -nofast -alpha -noalpha -version
51                     -help)
52             ;;
53         folder* )
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
57                     -help)
58             ;;
59         forw )
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
64                     -version -help)
65             ;;
66         inc )
67             options=(-audit -noaudit -changecur -nochangecur -form -format
68                     -file -silent -nosilent -truncate -notruncate -width
69                     -version -help)
70             ;;
71         mark )
72             options=(-sequence -add -delete -list -public -nopublic
73                     -zero -nozero -version -help)
74             ;;
75         next )
76             options=(-showmimeproc -header -noheader -checkmime
77                     -nocheckmime -version -help)
78             ;;
79         packf )
80             options=(-file -mbox -mmdf -version -help)
81             ;;
82         pick )
83             options=(-and -or -not -lbrace -rbrace --component -cc
84                     -date -from -search -subject -to -after -before -datefield
85                     -sequence -public -nopublic -zero -nozero -list -nolist
86                     -version -help)
87             ;;
88         prev )
89             options=(-showproc -showmimeproc -header -noheader -checkmime
90                     -nocheckmime -version -help)
91             ;;
92         refile )
93             options=(-draft -link -nolink -preserve -nopreserve -unlink
94                     -nounlink -src -file -rmmproc -normmproc -version -help)
95             ;;
96         repl )
97             options=(-annotate -noannotate -group -nogroup -cc
98                     -nocc -query -noquery -form -format -noformat -filter
99                     -inplace -noinplace -mime -nomime -fcc -width -draftfolder
100                     -draftmessage -nodraftfolder -editor -noedit -whatnowproc
101                     -nowhatnowproc -build -file -version -help)
102             ;;
103         rmf )
104             options=(-interactive -nointeractive -version -help)
105             ;;
106         rmm )
107             options=(-link -nolink -version -help)
108             ;;
109         scan )
110             options=(-clear -noclear -form -format -header -noheader
111                     -width -reverse -noreverse -file -version -help )
112             ;;
113         show )
114             options=(-draft -showproc -showmimeproc -header -noheader
115                     -checkmime -nocheckmime -version -help)
116             ;;
117         sortm )
118             options=(-datefield -textfield -notextfield -limit -nolimit
119                     -verbose -noverbose -version -help)
120             ;;
121         whom )
122             options=(-alias -check -nocheck -draft -draftfolder
123                     -draftmessage -nodraftfolder -version -help)
124             ;;
125         * )
126             options=(-help -version -seq)
127             ;;
128         esac
129         ;;
130
131     +* )
132         # Folders
133         options=( $( folder -all -r -fast | grep -v "^\." | sed "s/^/+/" ) )
134         ;;
135
136     +([0-9a-z])-* )
137         # Partial range
138         start=${current/%-*/}
139         options=( $( scan $folder -format "%(msg)" "${start}-last" ) first prev cur next last )
140         options=( ${options[@]//#/${start}-} )
141         ;;
142
143     +([0-9]) )
144         # Message number, or start of range
145         options=( $( scan $folder -format "%(msg)" ) first prev cur next last )
146         options=( ${options[@]} ${options[@]//%/-} )
147         ;;
148
149     [fpcnlu]* )
150         # special message aliases
151         options=( first prev cur next last unseen )
152         ;;
153
154         # What about sequences?  I can't quite see how to get the list of possible sequences, so I
155         # guess the user will have to type them in the old-fashioned way.
156
157     esac
158
159     eval $orig_opts
160
161     COMPREPLY=( $( compgen -W "${options[*]}" -- $current ) )
162     return 0
163 }
164 [ "$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 next packf pick prev prompter rcvdist rcvpack rcvstore rcvtty  refile repl rmf rmm scan send sendfiles show slocal sortm whatnow whom