Dropped old show(1) and renamed mhshow(1) to show(1).
[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 [ "$BASH_COMPLETION" ] || echo "ERROR: COMPLETION-BASH is not intended to be \
6 sourced directly, but rather added to a bash-completion package installation."
7
8 have show &&
9 _nmh()
10 {
11     # args: command comp-word prev-word
12     local command current prev folder origfolder i orig_opts
13
14     COMPREPLY=()
15     current=${COMP_WORDS[COMP_CWORD]}
16     prev=${COMP_WORDS[COMP_CWORD-1]}
17     command=$1
18
19     orig_opts=$(shopt -p extglob)
20     shopt -s extglob
21
22     # Get the folder, if specified
23     for (( i=0; i < ${#COMP_WORDS}-1; i++ ))
24     do
25         case "${COMP_WORDS[i]}" in
26         \++([a-zA-Z_]) )
27             folder=${COMP_WORDS[i]}
28             origfolder=$( folder -f )
29             ;;
30         esac
31     done
32
33     case $current in
34     -* )
35         # Command-line switches for the most common commands.
36         case $command in
37         ali )
38             # no sequences or messages
39             options=(-alias -list -nolist -normalize -nonormalize -user
40                     -nouser -version -help)
41             ;;
42         burst )
43             options=(-inplace -noinplace -quiet -noquiet -verbose
44                     -noverbose -version -help)
45             ;;
46         comp )
47             options=(-form -use -nouse
48                     -editor -noedit -whatnowproc -nowhatnowproc
49                     -version -help )
50            ;;
51         flist* )
52             options=(-sequence -all -noall -showzero -noshowzero
53                     -recurse -norecurse -fast -nofast -alpha -noalpha -version
54                     -help)
55             ;;
56         folder* )
57             options=(-all -noall -create -nocreate -fast -nofast -header
58                     -noheader -recurse -norecurse -total -nototal -list -nolist
59                     -push -pop -pack -nopack -print -verbose -noverbose
60                     -version -help)
61             ;;
62         forw )
63             options=(-annotate -noannotate -form
64                     -editor -noedit -whatnowproc
65                     -nowhatnowproc -build
66                     -version -help)
67             ;;
68         inc )
69             options=(-audit -noaudit -changecur -nochangecur -form
70                     -file -silent -nosilent -truncate -notruncate -width
71                     -version -help)
72             ;;
73         mark )
74             options=(-sequence -add -delete -list -public -nopublic
75                     -zero -nozero -version -help)
76             ;;
77         packf )
78             options=(-file -version -help)
79             ;;
80         pick )
81             options=(-and -or -not -lbrace -rbrace --component -cc
82                     -date -from -search -subject -to -after -before -datefield
83                     -sequence -public -nopublic -zero -nozero -list -nolist
84                     -version -help)
85             ;;
86         refile )
87             options=(-link -nolink -src -file -version -help)
88             ;;
89         repl )
90             options=(-annotate -noannotate -group -nogroup -cc
91                     -nocc -query -noquery -form -filter -nofilter
92                     -mime -nomime -editor -noedit -whatnowproc
93                     -nowhatnowproc -build -file -version -help)
94             ;;
95         rmf )
96             options=(-interactive -nointeractive -version -help)
97             ;;
98         rmm )
99             options=(-link -nolink -version -help)
100             ;;
101         scan )
102             options=(-form -header -noheader
103                     -width -file -version -help )
104             ;;
105         show )
106         next )
107         prev )
108             options=(-file -part -type -form -version -help)
109             ;;
110         sortm )
111             options=(-datefield -textfield -notextfield -limit -nolimit
112                     -verbose -noverbose -version -help)
113             ;;
114         * )
115             options=(-help -version -seq)
116             ;;
117         esac
118         ;;
119
120     +* )
121         # Folders
122         options=( $( folder -all -r -fast | grep -v "^\." | sed "s/^/+/" ) )
123         ;;
124
125     +([0-9a-z])-* )
126         # Partial range
127         start=${current/%-*/}
128         options=( $( scan $folder -form "=%(msg)" "${start}-last" ) first prev cur next last )
129         options=( ${options[@]//#/${start}-} )
130         ;;
131
132     +([0-9]) )
133         # Message number, or start of range
134         options=( $( scan $folder -form "=%(msg)" ) first prev cur next last )
135         options=( ${options[@]} ${options[@]//%/-} )
136         ;;
137
138     [fpcnlu]* )
139         # special message aliases
140         options=( first prev cur next last unseen )
141         ;;
142
143         # What about sequences?  I can't quite see how to get the list of possible sequences, so I
144         # guess the user will have to type them in the old-fashioned way.
145
146     esac
147
148     eval $orig_opts
149
150     COMPREPLY=( $( compgen -W "${options[*]}" -- $current ) )
151     return 0
152 }
153 [ "$have" ] && complete -F _nmh ali anno burst comp dist flist flists folder folders forw inc mark mhbuild mhl mhlist mhmail mhparam mhpath mhstore msgchk next packf pick prev prompter rcvdist rcvpack rcvstore refile repl rmf rmm scan send sendfiles show slocal sortm whatnow