blob: be3b1be7963c6688fcd37756b57814062d800e20 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
|
# cvs(1) completion
have cvs && {
set_prefix()
{
[ -z ${prefix:-} ] || prefix=${cur%/*}/
[ -r ${prefix:-}CVS/Entries ] || prefix=""
}
get_entries()
{
local IFS=$'\n'
[ -r ${prefix:-}CVS/Entries ] && \
entries=$(cut -d/ -f2 -s ${prefix:-}CVS/Entries)
}
get_modules()
{
if [ -n "$prefix" ]; then
COMPREPLY=( $( command ls -d ${cvsroot}/${prefix}/!(CVSROOT) ) )
else
COMPREPLY=( $( command ls -d ${cvsroot}/!(CVSROOT) ) )
fi
}
_cvs_commands()
{
cvs --help-commands 2>&1 | awk '/^( *|\t)/ { print $1 }'
}
_cvs_options()
{
cvs --help-options 2>&1 | awk '/^( *|\t)-/ { print $1 }'
}
_cvs_command_options()
{
cvs --help $1 2>&1 | sed -ne 's/^[[:space:]]*\(-[^[:space:]=[]*\).*/\1/p'
}
_cvs_kflags()
{
COMPREPLY=( $( compgen -W 'kv kvl k o b v' -- "$cur" ) )
}
_cvs_roots()
{
local -a cvsroots
cvsroots=( $CVSROOT )
[ -r ~/.cvspass ] && \
cvsroots=( "${cvsroots[@]}" $( awk '{ print $2 }' ~/.cvspass ) )
[ -r CVS/Root ] && cvsroots=( "${cvsroots[@]}" $(cat CVS/Root) )
COMPREPLY=( $( compgen -W '${cvsroots[@]}' -- "$cur" ) )
__ltrim_colon_completions "$cur"
}
_cvs()
{
local cur prev count mode i cvsroot cvsroots pwd
local -a flags miss files entries changed newremoved
COMPREPLY=()
_get_comp_words_by_ref -n : cur prev
count=0
for i in "${COMP_WORDS[@]}"; do
[ $count -eq $COMP_CWORD ] && break
# Last parameter was the CVSROOT, now go back to mode selection
if [[ "${COMP_WORDS[((count))]}" == "$cvsroot" && "$mode" == cvsroot ]]; then
mode=""
fi
if [ -z "$mode" ]; then
case $i in
-H|--help)
COMPREPLY=( $( compgen -W "$( _cvs_commands )" -- "$cur" ) )
return 0
;;
-d)
mode=cvsroot
cvsroot=${COMP_WORDS[((count+1))]}
;;
ad|add|new)
mode=add
;;
adm|admin|rcs)
mode=admin
;;
ann|annotate)
mode=annotate
;;
checkout|co|get)
mode=checkout
;;
com|commit|ci)
mode=commit
;;
di|dif|diff)
mode=diff
;;
ex|exp|export)
mode=export
;;
edit|unedit)
mode=$i
;;
hi|his|history)
mode=history
;;
im|imp|import)
mode=import
;;
re|rel|release)
mode=release
;;
log|rlog)
mode=log
;;
rdiff|patch)
mode=rdiff
;;
remove|rm|delete)
mode=remove
;;
rtag|rfreeze)
mode=rtag
;;
st|stat|status)
mode=status
;;
tag|freeze)
mode=tag
;;
up|upd|update)
mode=update
;;
esac
elif [[ "$i" = -* ]]; then
flags=( "${flags[@]}" $i )
fi
count=$((++count))
done
case $mode in
add)
case $prev in
-m)
return 0
;;
-k)
_cvs_kflags
return 0
;;
esac
if [[ "$cur" != -* ]]; then
set_prefix
if [[ $COMP_CWORD -gt 1 && -r ${prefix:-}CVS/Entries ]]; then
get_entries
[ -z "$cur" ] && \
files=$( command ls -Ad !(CVS) ) || \
files=$( command ls -d ${cur}* 2>/dev/null )
for i in "${entries[@]}"; do
files=( ${files[@]/#$i//} )
done
COMPREPLY=( $( compgen -X '*~' -W '${files[@]}' -- $cur ) )
fi
else
COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
-- "$cur" ) )
fi
;;
admin)
case $prev in
-a|-A|-b|-c|-e|-l|-m|-n|-N|-o|-s|-t-|-u)
return 0
;;
-t)
_filedir
return 0
;;
-k)
_cvs_kflags
return 0
;;
esac
if [[ "$cur" = -* ]]; then
COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
-- "$cur" ) )
fi
;;
annotate)
[[ "$prev" == -@(r|D) ]] && return 0
if [[ "$cur" = -* ]]; then
COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
-- "$cur" ) )
else
get_entries
COMPREPLY=( $( compgen -W '${entries[@]}' -- "$cur" ) )
fi
;;
checkout)
case $prev in
-r|-D|j)
return 0
;;
-d)
_filedir -d
return 0
;;
-k)
_cvs_kflags
return 0
;;
esac
if [[ "$cur" != -* ]]; then
[ -z "$cvsroot" ] && cvsroot=$CVSROOT
COMPREPLY=( $( cvs -d "$cvsroot" co -c 2> /dev/null | \
awk '{print $1}' ) )
COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
else
COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
-- "$cur" ) )
fi
;;
commit)
case $prev in
-m|-r)
return 0
;;
-F)
_filedir
return 0
;;
esac
set_prefix
if [[ "$cur" != -* && -r ${prefix:-}CVS/Entries ]]; then
# if $COMP_CVS_REMOTE is not null, 'cvs commit' will
# complete on remotely checked-out files (requires
# passwordless access to the remote repository
if [ -n "${COMP_CVS_REMOTE:-}" ]; then
# this is the least computationally intensive
# way found so far, but other changes
# (something other than changed/removed/new)
# may be missing
changed=( $( cvs -q diff --brief 2>&1 | \
sed -ne 's/^Files [^ ]* and \([^ ]*\) differ$/\1/p' ) )
newremoved=( $( cvs -q diff --brief 2>&1 | \
sed -ne 's/^cvs diff: \([^ ]*\) .*, no comparison available$/\1/p' ) )
COMPREPLY=( $( compgen -W '${changed[@]:-} \
${newremoved[@]:-}' -- "$cur" ) )
else
COMPREPLY=( $(compgen -o default -- "$cur") )
fi
else
COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
-- "$cur" ) )
fi
;;
cvsroot)
# TODO: works poorly because of the colons and -o default,
# could we drop -o default? works ok without it in cvsps
_cvs_roots
;;
export)
case $prev in
-r|-D)
return 0
;;
-d)
_filedir -d
return 0
;;
-k)
_cvs_kflags
return 0
;;
esac
if [[ "$cur" != -* ]]; then
[ -z "$cvsroot" ] && cvsroot=$CVSROOT
COMPREPLY=( $( cvs -d "$cvsroot" co -c | awk '{print $1}' ) )
COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
else
COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
-- "$cur" ) )
fi
;;
diff)
if [[ "$cur" == -* ]]; then
_longopt diff
else
get_entries
COMPREPLY=( $( compgen -W '${entries[@]:-}' -- "$cur" ) )
fi
;;
remove)
if [[ "$cur" != -* ]]; then
set_prefix
if [[ $COMP_CWORD -gt 1 && -r ${prefix:-}CVS/Entries ]]; then
get_entries
# find out what files are missing
for i in "${entries[@]}"; do
[ ! -r "$i" ] && miss=( "${miss[@]}" $i )
done
COMPREPLY=( $(compgen -W '${miss[@]:-}' -- "$cur") )
fi
else
COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
-- "$cur" ) )
fi
;;
import)
case $prev in
-I|-b|-m|-W)
return 0
;;
-k)
_cvs_kflags
return 0
;;
esac
if [[ "$cur" != -* ]]; then
# starts with same algorithm as checkout
[ -z "$cvsroot" ] && cvsroot=$CVSROOT
prefix=${cur%/*}
if [ -r ${cvsroot}/${prefix} ]; then
get_modules
COMPREPLY=( ${COMPREPLY[@]#$cvsroot} )
COMPREPLY=( ${COMPREPLY[@]#\/} )
fi
pwd=$( pwd )
pwd=${pwd##*/}
COMPREPLY=( $( compgen -W '${COMPREPLY[@]} $pwd' -- $cur ) )
else
COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
-- "$cur" ) )
fi
;;
update)
case $prev in
-r|-D|-j|-I|-W)
return 0
;;
-k)
_cvs_kflags
return 0
;;
esac
if [[ "$cur" = -* ]]; then
COMPREPLY=( $( compgen -W "$( _cvs_command_options $mode )" \
-- "$cur" ) )
fi
;;
"")
case $prev in
-T)
_filedir -d
return 0
;;
-e|-s)
return 0
;;
-z)
COMPREPLY=( $( compgen -W '1 2 3 4 5 6 7 8 9' -- "$cur" ) )
return 0
;;
esac
COMPREPLY=( $( compgen -W '$( _cvs_commands ) $( _cvs_options ) \
--help --help-commands --help-options --version' -- "$cur" ) )
;;
esac
return 0
}
complete -F _cvs -o default cvs
}
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh
|