]> diplodocus.org Git - nmh/blob - docs/COMPLETION-BASH
We're not using the .Bu macro anymore.
[nmh] / 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 -host
69 -user -pack -nopack -apop -noapop -kpop -sasl -saslmech -snoop
70 -version -help)
71 ;;
72 mark )
73 options=(-sequence -add -delete -list -public -nopublic
74 -zero -nozero -version -help)
75 ;;
76 next )
77 options=(-showmimeproc -header -noheader -checkmime
78 -nocheckmime -version -help)
79 ;;
80 packf )
81 options=(-file -mbox -mmdf -version -help)
82 ;;
83 pick )
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
87 -version -help)
88 ;;
89 prev )
90 options=(-showproc -showmimeproc -header -noheader -checkmime
91 -nocheckmime -version -help)
92 ;;
93 refile )
94 options=(-draft -link -nolink -preserve -nopreserve -unlink
95 -nounlink -src -file -rmmproc -normmproc -version -help)
96 ;;
97 repl )
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)
103 ;;
104 rmf )
105 options=(-interactive -nointeractive -version -help)
106 ;;
107 rmm )
108 options=(-link -nolink -version -help)
109 ;;
110 scan )
111 options=(-clear -noclear -form -format -header -noheader
112 -width -reverse -noreverse -file -version -help )
113 ;;
114 show )
115 options=(-draft -showproc -showmimeproc -header -noheader
116 -checkmime -nocheckmime -version -help)
117 ;;
118 sortm )
119 options=(-datefield -textfield -notextfield -limit -nolimit
120 -verbose -noverbose -version -help)
121 ;;
122 whom )
123 options=(-alias -check -nocheck -draft -draftfolder
124 -draftmessage -nodraftfolder -version -help)
125 ;;
126 * )
127 options=(-help -version -seq)
128 ;;
129 esac
130 ;;
131
132 +* )
133 # Folders
134 options=( $( folder -all -r -fast | grep -v "^\." | sed "s/^/+/" ) )
135 ;;
136
137 +([0-9a-z])-* )
138 # Partial range
139 start=${current/%-*/}
140 options=( $( scan $folder -format "%(msg)" "${start}-last" ) first prev cur next last )
141 options=( ${options[@]//#/${start}-} )
142 ;;
143
144 +([0-9]) )
145 # Message number, or start of range
146 options=( $( scan $folder -format "%(msg)" ) first prev cur next last )
147 options=( ${options[@]} ${options[@]//%/-} )
148 ;;
149
150 [fpcnlu]* )
151 # special message aliases
152 options=( first prev cur next last unseen )
153 ;;
154
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.
157
158 esac
159
160 eval $orig_opts
161
162 COMPREPLY=( $( compgen -W "${options[*]}" -- $current ) )
163 return 0
164 }
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