about summary refs log tree commit diff
path: root/Completion/User/_cvs
blob: 484d5c88cecb0e44c0ddc0b3fce9240d6aa4ec92 (plain) (blame)
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
#compdef cvs

# redefine _cvs.

_cvs () {
  # "+Qqrwtnlvb:T:e:d:Hfz:s:xa"
  _arguments -s \
    -{a,f,H,l,n,Q,q,r,t,v,w,x} \
    '--version' '--help' '--help-commands' '--help-synonyms' '--help-options' \
    '--allow-root=:rootdir:_files -/' \
    '-b+:bindir:_cvs_bindir' \
    '-T+:temporary directory:_cvs_tempdir' \
    '-d+:cvsroot:_cvs_root' \
    '-e+:editor:_cvs_editor' \
    '-s+:user variable:_cvs_user_variable' \
    '-z+:gzip level:_cvs_gzip_level' \
    '*::cvs command:_cvs_command'
}

# define cvs command dispatch function.

(( $+functions[_cvs_command] )) ||
_cvs_command () {
  typeset -A cmds
  cmds=(add " ad new "          admin " adm rcs "       annotate " ann "
	checkout " co get "     commit " ci com "       diff " di dif "
	edit ""                 editors ""              export " exp ex "
	history " hi his "      import " im imp "       init ""
	log " lo rlog "         login " logon lgn "     logout ""
	rdiff " patch pa "      release " re rel "      remove " rm delete "
	status " st stat "      rtag " rt rfreeze "     tag " ta freeze "
	unedit ""               update " up upd "       watch ""
	watchers "")

  if (( CURRENT == 1 )); then
    _tags commands && { compadd "$@" ${(k)cmds} || compadd "$@" ${(kv)=cmds} }
  else
    local curcontext="$curcontext"

    curcontext="${curcontext%:*}:$words[1]"
    _cvs_"${${(k)cmds[(R)* $words[1] *]}:-${(k)cmds[(i)$words[1]]}}"
  fi
}

_cvs_ () {
  _message "unknown cvs command: $words[1]"
}

# define completion functions for each cvs command

(( $+functions[_cvs_add] )) ||
_cvs_add () {
  # "+k:m:"
  _arguments -s \
    '-k+:keyword substitution:_cvs_k' \
    '-m+:message:_cvs_m' \
    '*:file:_cvs_files_unmaintained' \
}

(( $+functions[_cvs_admin] )) ||
_cvs_admin () {
  # "+ib::c:a:A:e:l::u::LUn:N:m:o:s:t::IqxV:k:"
  _arguments -s \
    -{i,L,U,I,q,x} \
    '-b-:default branch:(1.1.1)' \
    '-c+:comment leader (not used):' \
    '-a+:login names (not work with CVS):' \
    '-A+:access list to append (not work with CVS):' \
    '-e+:access list to erase (not work with CVS):' \
    '-l-:revision to lock:' \
    '-u-:revision to unlock:' \
    '-n+:symbolic-name(\:revision):' \
    '-N+:symbolic-name(\:revision):' \
    '-m+:revision\:msg:' \
    '-o+:range to delete:' \
    '-s+:state(\:revision):' \
    '-t-:descriptive text:_cvs_admin_t' \
    '-V+:version (obsolete):' \
    '-k+:keyword substitution:_cvs_k' \
    '*:file:_cvs_files'
}

(( $+functions[_cvs_admin_t] )) ||
_cvs_admin_t () {
  if compset -P -; then
    _message 'descriptive text'
  else
    _files "$@"
  fi
}

(( $+functions[_cvs_annotate] )) ||
_cvs_annotate () {
  # "+lr:D:fR"
  _arguments -s \
    -{l,f,R} \
    '-r+:tag:_cvs_revisions' \
    '-D+:date:_cvs_D' \
    '*:file:_cvs_files'
}

(( $+functions[_cvs_checkout] )) ||
_cvs_checkout () {
  # "+ANnk:d:flRpQqcsr:D:j:P"
  _arguments -s \
    -{A,N,n,f,l,R,q,c,s,P} \
    '-k+:keyword substitution:_cvs_k' \
    '-d+:directory:_files -/' \
    '-r+:tag:_cvs_revisions' \
    '-D+:date:_cvs_D' \
    '-j+:tag:_cvs_revisions' \
    '*:module:_cvs_modules'
}

(( $+functions[_cvs_commit] )) ||
_cvs_commit () {
  # "+nlRm:fF:r:"
  _arguments -s \
    -{n,l,R,f} \
    '-m+:message:_cvs_m' \
    '-F+:log message file:_files' \
    '-r+:tag:_cvs_revisions' \
    '*:file:_cvs_files_modified'
}

(( $+functions[_cvs_diff] )) ||
_cvs_diff () {
  # "+abcdefhilnpstuw0123456789BHNRC:D:F:I:L:U:V:W:k:r:"
  _arguments -s \
    -{l,R} \
    '-D+:date:_cvs_D' \
    '-k+:keyword substitution:_cvs_k' \
    '-r+:tag:_cvs_revisions' \
    -{h,p,0,1,2,3,4,5,6,7,8,9} \
    '--binary' \
    '--brief' \
    '--changed-group-format=:format:' \
    '-c' '-C+:lines:' '--context=-:lines:' \
    '-e' '--ed' \
    '-t' '--expand-tabs' \
    '-f' '--forward-ed' \
    '--horizon-lines=:lines:' \
    '--ifdef=:name:' \
    '-w' '--ignore-all-space' \
    '-B' '--ignore-blank-lines' \
    '-i' '--ignore-case' \
    '-I+:regex:' '--ignore-matching-lines=:regex:' \
    '-b' '--ignore-space-change' \
    '--initial-tab' \
    '*-L+:label:' '*--label=:label:' \
    '--left-column' \
    '--line-format=:format:' \
    '-d' '--minimal' \
    '-N' '--new-file' \
    '--new-group-format=:format:' \
    '--new-line-format=:format:' \
    '--old-group-format=:format:' \
    '--old-line-format=:format:' \
    '--paginate' \
    '-n' '--rcs' \
    '-s' '--report-identical-files' \
    '--show-c-function' \
    '-F+:regex:' '--show-function-line=:regex:' \
    '-y' '--side-by-side' \
    '-H' '--speed-large-files' \
    '--suppress-common-lines' \
    '-a' '--text' \
    '--unchanged-group-format=:format:' \
    '--unchanged-line-format=:format:' \
    '-u' '-U+:lines:' '--unified=-:lines:' \
    '-W:columns:' '--width=:columns:' \
    '*:file:_cvs_diff_arg'
}

(( $+functions[_cvs_diff_arg] )) ||
_cvs_diff_arg () {
  _cvs_files_modified || _cvs_files
}

(( $+functions[_cvs_edit] )) ||
_cvs_edit () {
  # "+lRa:"
  _arguments -s \
    -{l,R} \
    '-a+:action:(edit unedit commit all none)' \
    '*:file:_cvs_files'
}

(( $+functions[_cvs_editors] )) ||
_cvs_editors () {
  # "+lR"
  _arguments -s \
    -{l,R} \
    '*:file:_cvs_files'
}

(( $+functions[_cvs_export] )) ||
_cvs_export () {
  # "+Nnk:d:flRQqr:D:"
  _arguments -s \
    -{N,n,f,l,R,Q,q} \
    '-k+:keyword substitution:_cvs_k' \
    '-d+:directory:_files -/' \
    '-r+:tag:_cvs_revisions' \
    '-D+:date:_cvs_D' \
    '*:module:_cvs_modules'
}

(( $+functions[_cvs_history] )) ||
_cvs_history () {
  # "+Tacelow?D:b:f:m:n:p:r:t:u:x:X:z:"
  _arguments -s \
    -{T,a,c,e,l,o,w,\?} \
    '-D+:date:_cvs_D' \
    '-b+:string:' \
    '-f+:arg:' \
    '-m+:module:_cvs_modules' \
    '-n+:arg:' \
    '*-p+:repository:' \
    '-r+:rev:' \
    '-t+:tag:' \
    '-u+:user name:' \
    '-x+:type:_cvs_history_x' \
    '-X+:arg:' \
    '-z+:arg:' \
    '*:file:_cvs_files'
}

(( $+functions[_cvs_history_x] )) ||
_cvs_history_x () {
  _values -s '' 'type' \
    'F[release]' \
    'O[checkout]' \
    'E[export]' \
    'T[rtag]' \
    'C[merge collision-detected]' \
    'G[merge succeed]' \
    'U[working file was copied]' \
    'W[working file was deleted]' \
    'A[A file was added]' \
    'M[A file was modified]' \
    'R[A file was removed]'
}

(( $+functions[_cvs_import] )) ||
_cvs_import () {
  # "+Qqdb:m:I:k:W:"
  _arguments -s \
    -{Q,q,d} \
    '-b+:branch:' \
    '-m+:message:_cvs_m' \
    '*-I+:name:_files' \
    '-k+:keyword substitution:_cvs_k' \
    '*-W+:spec:' \
    ':repository:_cvs_modules' \
    ':vendor tag:' \
    ':release tag:'
}

(( $+functions[_cvs_init] )) ||
_cvs_init () {
  false
}

(( $+functions[_cvs_log] )) ||
_cvs_log () {
  # "+bd:hlNRr::s:tw::"
  _arguments -s \
    -{b,h,l,N,R,t} \
    '-d+:dates:' \
    '-r-:revisions:' \
    '-s+:states:' \
    '-w-:logins:' \
    '*:file:_cvs_files'
}

(( $+functions[_cvs_login] )) ||
_cvs_login () {
  false
}

(( $+functions[_cvs_logout] )) ||
_cvs_logout () {
  false
}

(( $+functions[_cvs_rdiff] )) ||
_cvs_rdiff () {
  # "+V:k:cuftsQqlRD:r:"
  _arguments -s \
    -{c,u,f,t,s,Q,q,l,R} \
    '-V+:version:' \
    '-k+:keyword substitution:_cvs_k' \
    '*-D+:date:_cvs_D' \
    '*-r+:tag:_cvs_revisions' \
    '*:module:_cvs_modules'
}

(( $+functions[_cvs_release] )) ||
_cvs_release () {
  # "+Qdq"
  _arguments -s \
    -{Q,d,q} \
    '*:directory:_files -/'
}

(( $+functions[_cvs_remove] )) ||
_cvs_remove () {
  # "+flR"
  _arguments -s \
    -{f,l,R} \
    '*:file:_cvs_files_removed'
}

(( $+functions[_cvs_status] )) ||
_cvs_status () {
  # "+vlR"
  _arguments -s \
    -{v,l,R} \
    '*:file:_cvs_files'
}

(( $+functions[_cvs_tag] )) ||
_cvs_tag () {
  # "+FQqlRcdr:D:bf"
  _arguments -s \
    -{F,Q,q,l,R,c,d,b,f} \
    '-r+:tag:_cvs_revisions' \
    '-D+:date:_cvs_D' \
    ':tag:' \
    '*:file:_cvs_files'
}

(( $+functions[_cvs_unedit] )) ||
_cvs_unedit () {
  # "+lR"
  _arguments -s \
    -{l,R} \
    '*:file:_cvs_files'
}

(( $+functions[_cvs_update] )) ||
_cvs_update () {
  # "+ApPflRQqduk:r:D:j:I:W:"
  _arguments -s \
    -{A,p,P,f,l,R,Q,q,d,u} \
    '-k+:keyword substitution:_cvs_k' \
    '-r+:tag:_cvs_revisions' \
    '-D+:date:_cvs_D' \
    '-j+:tag:_cvs_revisions' \
    '*-I+:name:_files' \
    '*-W+:spec:' \
    '*:file:_cvs_files'
}

(( $+functions[_cvs_watch] )) ||
_cvs_watch () {
  local expl

  if (( CURRENT == 2 )); then
    _wanted values expl 'watch comamnd' && compadd on off add remove
  else
    case "$words[2]" in
      on|off) # "+lR"
	_arguments -s \
	    -{l,R} \
	    ':watch command:' \
	    '*:file:_cvs_files'
	;;
      add|remove) # "+lRa:"
	_arguments -s \
	    -{l,R} \
	    '*-a+:action:(edit unedit commit all none)' \
	    ':watch command:' \
	    '*:file:_cvs_files'
	;;
    esac
  fi
}

(( $+functions[_cvs_watchers] )) ||
_cvs_watchers () {
  # "+lR"
  _arguments -s \
      -{l,R} \
      '*:file:_cvs_files'
}

(( $+functions[_cvs_root] )) ||
_cvs_root () {
  _tags files && { compadd "$@" $_cvs_roots || _files "$@" -/ }
}

(( $+functions[_cvs_tempdir] )) ||
_cvs_tempdir () {
  _tags directories && compadd "$@" $TMPPREFIX:h $TMPDIR /tmp
}

(( $+functions[_cvs_user_variable] )) ||
_cvs_user_variable () {
  if compset -P '*='; then
    _default
  else
    _message "variable=value"
  fi
}

# define completion functions for cvs global options.

(( $+functions[_cvs_bindir] )) ||
_cvs_bindir () {
  _tags directories && { compadd "$@" /usr/local/bin || _files "$@" -/ }
}

(( $+functions[_cvs_editor] )) ||
_cvs_editor () {
  _tags commands && compadd "$@" vi
}

(( $+functions[_cvs_gzip_level] )) ||
_cvs_gzip_level () {
  _tags values && compadd "$@" 9
}

# define completion functions for cvs common options and arguments.

(( $+functions[_cvs_D] )) ||
_cvs_D () {
  _tags values && compadd "$@" today yesterday week\ ago month\ ago
}

(( $+functions[_cvs_k] )) ||
_cvs_k () {
  _tags values && compadd "$@" kv kvl k o b v
}

(( $+functions[_cvs_m] )) ||
_cvs_m () {
  _message "log message"
}

(( $+functions[_cvs_modules] )) ||
_cvs_modules () {
  local root=$CVSROOT expl

  [[ -f CVS/Root ]] && root=$(<CVS/Root)

  if [[ $root = :* || ! -d $root ]]; then
    _message "module name"
  else
    _wanted modules expl module &&
        compadd "$expl[@]" - \
            $root/^CVSROOT(:t) \
            ${${(M)${(f)"$(<$root/CVSROOT/modules)"}:#[^#]*}%%[ 	]*}
  fi
}

(( $+functions[_cvs_revisions] )) ||
_cvs_revisions () {
  local expl

  _wanted values expl revision &&
      compadd - ${${${(M)${(f)"$(cvs -q status -vl .)"}:#	*}##[ 	]##}%%[ 	]*}
}

# define completion functions for files maintained by cvs.

(( $+functions[_cvs_setup_prefix] )) ||
_cvs_setup_prefix () {
  if [[ -prefix */ ]]; then
    qpref="${PREFIX%/*}/"
    pref=$~qpref
  else
    qpref=
    pref=./
  fi
}

(( $+functions[_cvs_extract_directory_entries] )) ||
_cvs_extract_directory_entries () {
  entries=($entries ${${${(M)rawentries:#D/*}#D/}%%/*})
}

(( $+functions[_cvs_extract_file_entries] )) ||
_cvs_extract_file_entries () {
  entries=($entries ${${${(M)rawentries:#/*}#/}%%/*})
}

(( $+functions[_cvs_extract_modifiedfile_entries] )) ||
_cvs_extract_modifiedfile_entries () {
  if _style cvs disable-stat || ! { zmodload -e stat || zmodload stat }; then
    _cvs_extract_file_entries
    return
  fi

  local ents pats
  ents=(${${${${(M)rawentries:#/*}#/}/\\/[^\\/]#\\///}%/[^/]#/[^/]#})
  pats=(${${${(f)"$(LANG=C builtin stat -gn +mtime -F '%a %b %e %T %Y' ${pref}*(D))"}##*/}/ //})
  eval 'ents=(${ents:#('${(j:|:)${(@)pats:q}}')})'
  entries=($entries ${ents%%/*})
}

(( $+functions[_cvs_setup_allentries] )) ||
_cvs_setup_allentries () {
  entries=()
  if [[ -f ${pref}CVS/Entries ]]; then
    local rawentries
    rawentries=(${(f)"$(<${pref}CVS/Entries)"})
    _cvs_extract_file_entries
    _cvs_extract_directory_entries
  fi
}

(( $+functions[_cvs_setup_direntries] )) ||
_cvs_setup_direntries () {
  entries=()
  if [[ -f ${pref}CVS/Entries ]]; then
    local rawentries
    rawentries=(${(f)"$(<${pref}CVS/Entries)"})
    _cvs_extract_directory_entries
  fi
}

(( $+functions[_cvs_setup_modentries] )) ||
_cvs_setup_modentries () {
  entries=()
  if [[ -f ${pref}CVS/Entries ]]; then
    local rawentries
    rawentries=(${(f)"$(<${pref}CVS/Entries)"})
    _cvs_extract_modifiedfile_entries
    _cvs_extract_directory_entries
  fi
}

(( $+functions[_cvs_directories] )) ||
_cvs_directories () {
  if [[ -d ${pref}CVS ]]; then
    _cvs_setup_direntries
    (( $#entries )) && _files "$@" -g "${(j:|:)${(@)entries:q}}"
  else
    _files "$@"
  fi
}

(( $+functions[_cvs_files] )) ||
_cvs_files () {
  local qpref pref entries
  _cvs_setup_prefix
  if [[ -d ${pref}CVS ]]; then
    _cvs_setup_allentries
    (( $#entries )) && _files "$@" -g "${(j:|:)${(@)entries:q}}"
  else
    _files "$@"
  fi
}

(( $+functions[_cvs_files_modified] )) ||
_cvs_files_modified () {
  local qpref pref entries
  _cvs_setup_prefix
  if [[ -d ${pref}CVS ]]; then
    _cvs_setup_modentries
    (( $#entries )) && _files "$@" -g "${(j:|:)${(@)entries:q}}"
  else
    _files "$@"
  fi
}

(( $+functions[_cvs_files_removed] )) ||
_cvs_files_removed () {
  local qpref pref entries
  _cvs_setup_prefix
  if [[ -d ${pref}CVS ]]; then
    _cvs_setup_allentries
    setopt localoptions unset
    local omit
    omit=(${pref}*(D:t))
    eval 'entries=(${entries:#('${(j:|:)${(@)omit:q}}')})'
    _tags directories && compadd "$@" -P "$qpref" - ${entries:q} ||
    _cvs_directories "$@"
  else
    _files "$@"
  fi
}

(( $+functions[_cvs_files_unmaintained] )) ||
_cvs_files_unmaintained () {
  local qpref pref entries
  _cvs_setup_prefix
  if [[ -d ${pref}CVS ]]; then
    _cvs_setup_allentries
    setopt localoptions unset
    local omit
    omit=($_cvs_ignore_default ${entries:q} ${=cvsignore})
    [[ -r ~/.cvsignore ]] && omit=($omit $(<~/.cvsignore))
    [[ -r ${pref}.cvsignore ]] && omit=($omit $(<${pref}.cvsignore))
    _files "$@" -g '*~(*/|)('${(j:|:)omit}')(D)' ||
    _files "$@" -g '*~(*/|)('${(j:|:)${(@)entries:q}}')(D)' ||
    _cvs_directories "$@"
  else
    _files "$@"
  fi
}

# define configuration variables.

local tmp

(( $+_cvs_roots )) ||
if [[ -f "${tmp::=${CVS_PASSFILE:-$HOME/.cvspass}}" ]]; then
  _cvs_roots=(${${(f)"$(<$tmp)"}%% *})
else
  _cvs_roots=()
fi

(( $+_cvs_ignore_default )) ||
_cvs_ignore_default=(
  RCS SCCS CVS CVS.adm RCSLOG 'cvslog.*' tags TAGS .make.state .nse_depinfo
  '*\~' '\#*' '.\#*' ',*' '_$*' '*$' '*.old' '*.bak' '*.BAK' '*.orig' '*.rej'
  '.del-*' '*.a' '*.olb' '*.o' '*.obj' '*.so' '*.exe' '*.Z' '*.elc' '*.ln'
  core
)

# call real _cvs.

_cvs "$@"