Imported from ../bash-2.05.tar.gz.
[platform/upstream/bash.git] / examples / complete / complete2.ianmac
1 #####
2 #From: ian@linuxcare.com (Ian Macdonald)
3 #Newsgroups: comp.unix.shell
4 #Subject: More bash 2.04 completions
5 #Date: 12 Aug 2000 09:53:40 GMT
6 #Organization: Linuxcare, Inc.
7 #Lines: 274
8 #Message-ID: <slrn8pa7l2.jgm.ian@lovelorn.linuxcare.com>
9 #Reply-To: ian@linuxcare.com
10 #####
11
12 # Turn on extended globbing
13 shopt -s extglob
14
15 # cvs(1) completion
16 #
17 _cvs ()
18 {
19         local cur prev
20
21         COMPREPLY=()
22         cur=${COMP_WORDS[COMP_CWORD]}
23         prev=${COMP_WORDS[COMP_CWORD-1]}
24
25         if [ $COMP_CWORD -eq 1 ] || [ "${prev:0:1}" = "-" ]; then
26                 COMPREPLY=( $( compgen -W 'add admin checkout commit diff \
27                 export history import log rdiff release remove rtag status \
28                 tag update' $cur ))
29         else
30                 COMPREPLY=( $( compgen -f $cur ))
31         fi
32         return 0
33 }
34 complete -F _cvs cvs
35
36 # rpm(8) completion. This isn't exhaustive yet, but still provides
37 # quite a lot of functionality.
38
39 _rpm()
40 {
41         dashify()
42         {
43                 local i
44
45                 for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
46                         if [ ${#COMPREPLY[i]} -le 2 ]; then
47                                 COMPREPLY[i]=-${COMPREPLY[i]}
48                         else
49                                 COMPREPLY[i]=--${COMPREPLY[i]}
50                         fi
51                 done
52         }
53
54         local cur cur_nodash prev
55
56         COMPREPLY=()
57         cur=${COMP_WORDS[COMP_CWORD]}
58         cur_nodash=${cur#-}
59         prev=${COMP_WORDS[COMP_CWORD-1]}
60
61         if [ $COMP_CWORD = 1 ]; then
62                 # first parameter on line
63                 case "$cur" in
64                 -b*)
65                         COMPREPLY=( $( compgen -W 'ba bb bc bi bl bp bs' \
66                                        $cur_nodash ) )
67                         dashify
68                         return 0
69                         ;;
70                 -t*)
71                         COMPREPLY=( $( compgen -W 'ta tb tc ti tl tp ts' \
72                                        $cur_nodash ) )
73                         dashify
74                         return 0
75                         ;;
76                 --*)
77                         COMPREPLY=( $( compgen -W 'help version initdb \
78                         checksig recompile rebuild resign addsign rebuilddb \
79                         showrc setperms setgids' ${cur_nodash#-} ) )
80                         dashify;
81                         return 0
82                         ;;
83                 *)
84                         COMPREPLY=( $( compgen -W 'b e F i q t U V' \
85                                        $cur_nodash ) )
86                         dashify
87                         return 0
88                         ;;
89                 esac
90         fi
91
92         case "${COMP_WORDS[1]}" in
93         -[iFU]*)
94                 # complete on list of relevant options
95                 COMPREPLY=( $( compgen -W 'percent force test replacepkgs \
96                 replacefiles root excludedocs includedocs noscripts rcfile \
97                 ignorearch dbpath prefix ignoreos nodeps allfiles ftpproxy \
98                 ftpport justdb httpproxy httpport noorder relocate badreloc \
99                 notriggers excludepath ignoresize oldpackage' ${cur_nodash#-} ))
100                 dashify;
101                 # return if $cur is an option
102                 [ "${cur:0:1}" = "-" ] && return 0
103                 # add a list of RPMS to possible completions
104                 COMPREPLY=( ${COMPREPLY[@]} $( compgen -G $cur\*.rpm ) )
105                 return 0
106                 ;;
107         -qp*)
108                 # complete on list of relevant options
109                 COMPREPLY=( $( compgen -W 'scripts root rcfile whatprovides \
110                 whatrequires requires triggeredby ftpport ftpproxy httpproxy \
111                 httpport provides triggers dump changelog dbpath filesbypkg' \
112                 ${cur_nodash#-} ) )
113                 dashify;
114                 # return if $cur is an option
115                 [ "${cur:0:1}" = "-" ] && return 0
116                 # add a list of RPMS to possible completions
117                 COMPREPLY=( ${COMPREPLY[@]} $( compgen -G $cur\*.rpm ) )
118                 return 0
119                 ;;
120         -*f)
121                 # standard filename completion
122                 COMPREPLY=( $( compgen -f $cur ) )
123                 return 0
124                 ;;
125         -e)
126                 # complete on list of relevant options
127                 COMPREPLY=( $( compgen -W 'allmatches noscripts notriggers \
128                 nodeps test' ${cur_nodash#-} ) )
129                 dashify;
130                 # return if $cur is an option
131                 [ "${cur:0:1}" = "-" ] && return 0
132                 # complete on basename of installed RPMs
133                 COMPREPLY=( $( rpm -qa | \
134                    sed -ne 's/^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9.]\+$/\1/p' ) )
135                 return 0
136                 ;;
137         -qa*)
138                 # complete on list of relevant options
139                 COMPREPLY=( $( compgen -W 'scripts root rcfile whatprovides \
140                 whatrequires requires triggeredby ftpport ftpproxy httpproxy \
141                 httpport provides triggers dump changelog dbpath specfile \
142                 querybynumber last filesbypkg' ${cur_nodash#-} ) )
143                 dashify;
144                 return 0
145                 ;;
146         -q*)
147                 # complete on list of relevant options
148                 COMPREPLY=( $( compgen -W 'scripts root rcfile whatprovides \
149                 whatrequires requires triggeredby ftpport ftpproxy httpproxy \
150                 httpport provides triggers dump changelog dbpath specfile \
151                 querybynumber last filesbypkg' ${cur_nodash#-} ) )
152                 dashify;
153                 # return if $cur is an option
154                 [ "${cur:0:1}" = "-" ] && return 0
155                 # add a list of RPMS to possible completions
156                 COMPREPLY=( ${COMPREPLY[@]} $( rpm -qa | \
157                    sed -ne 's/^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9.]\+$/\1/p' ) )
158                 return 0
159                 ;;
160         -[Vy]*)
161                 # complete on list of relevant options
162                 COMPREPLY=( $( compgen -W 'root rcfile dbpath nodeps nofiles \
163                 noscripts nomd5 nopgp' ${cur_nodash#-} ) )
164                 dashify;
165                 # return if $cur is an option
166                 [ "${cur:0:1}" = "-" ] && return 0
167                 # add a list of RPMS to possible completions
168                 COMPREPLY=( ${COMPREPLY[@]} $( rpm -qa | \
169                    sed -ne 's/^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9.]\+$/\1/p' ) )
170                 return 0
171                 ;;
172         -b*)
173                 # complete on list of relevant options
174                 COMPREPLY=( $( compgen -W 'short-circuit timecheck clean \
175                 rmsource test sign buildroot target buildarch buildos' \
176                 ${cur_nodash#-} ) )
177                 dashify;
178                 # return if $cur is an option
179                 [ "${cur:0:1}" = "-" ] && return 0
180                 # complete on .spec files
181                 COMPREPLY=( $( compgen -G $cur\*.spec ) )
182                 return 0
183                 ;;
184         -t*)
185                 # complete on list of relevant options
186                 COMPREPLY=( $( compgen -W 'short-circuit timecheck clean \
187                 rmsource test sign buildroot target buildarch buildos' \
188                 ${cur_nodash#-} ) )
189                 dashify;
190                 # return if $cur is an option
191                 [ "${cur:0:1}" = "-" ] && return 0
192                 # complete on .tar.gz files
193                 COMPREPLY=( $( compgen -G $cur\*.tar.gz ) )
194                 return 0
195                 ;;
196         --re@(build|compile))
197                 # complete on source RPMs
198                 COMPREPLY=( $( compgen -G $cur\*.src.rpm ) )
199                 return 0
200                 ;;
201         --@(checksig|@(re|add)sign))
202                 # complete on RPMs
203                 COMPREPLY=( $( compgen -G $cur\*.rpm ) )
204                 return 0
205                 ;;
206         --set@(perms|gids))
207                 # complete on installed RPMs
208                 COMPREPLY=( ${COMPREPLY[@]} $( rpm -qa | \
209                    sed -ne 's/^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9.]\+$/\1/p' ) )
210                 return 0
211                 ;;
212         esac
213 }
214 complete -F _rpm rpm
215
216 # chsh(1) completion
217 #
218 _chsh()
219 {
220         local cur prev
221
222         COMPREPLY=()
223         cur=${COMP_WORDS[COMP_CWORD]}
224         prev=${COMP_WORDS[COMP_CWORD-1]}
225
226         if [ "$prev" = "-s" ]; then
227                 COMPREPLY=( $( chsh -l | grep ^$cur ) )
228         else
229                 COMPREPLY=( $( compgen -u $cur ) )
230         fi
231 }
232 complete -F _chsh chsh
233
234 # chkconfig(8) completion
235 #
236 _chkconfig()
237 {
238         local cur prev
239
240         COMPREPLY=()
241         cur=${COMP_WORDS[COMP_CWORD]}
242         cur_nodash=${cur#--}
243         prev=${COMP_WORDS[COMP_CWORD-1]}
244
245         if [ $COMP_CWORD -eq 1 ]; then
246                 COMPREPLY=( $( compgen -W 'list add del level' $cur_nodash ) )
247                 for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
248                         COMPREPLY[i]=--${COMPREPLY[i]}
249                 done
250                 return 0
251         fi
252
253         if [ $COMP_CWORD -eq 4 ]; then
254                 COMPREPLY=( $( compgen -W 'on off reset' $cur ) )
255                 return 0
256         fi
257
258         case "$prev" in
259         @([1-6]|--@(list|add|del)))
260                 COMPREPLY=( $( compgen -W "`(cd /etc/rc.d/init.d; echo *)`" \
261                                $cur) )
262                 return 0
263                 ;;
264         --level)
265                 COMPREPLY=( $( compgen -W '1 2 3 4 5 6' $cur ) )
266                 return 0
267                 ;;
268         esac
269 }
270 complete -F _chkconfig chkconfig
271 ###