-
Notifications
You must be signed in to change notification settings - Fork 3
/
p4-completion.sh
2108 lines (1917 loc) · 51.6 KB
/
p4-completion.sh
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
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# A bash completion script for Perforce 2015.2
# Author: Zach Whaley, [email protected]
# Turn on extended globbing and programmable completion
shopt -s extglob progcomp
# If bash-completion is not installed, use the functionality from bash-completion 1.3
# Copied from https://github.com/scop/bash-completion/blob/7c81ef895455d0f7543c65789ff62808e7465578/bash_completion
if ! type _init_completion &>/dev/null; then
#
# bash_completion - programmable completion functions for bash 3.2+
#
# Copyright © 2006-2008, Ian Macdonald <[email protected]>
# © 2009-2011, Bash Completion Maintainers
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# The latest version of this software can be obtained here:
#
# http://bash-completion.alioth.debian.org/
#
# RELEASE: 1.3
# Assign variable one scope above the caller
# Usage: local "$1" && _upvar $1 "value(s)"
# Param: $1 Variable name to assign value to
# Param: $* Value(s) to assign. If multiple values, an array is
# assigned, otherwise a single value is assigned.
# NOTE: For assigning multiple variables, use '_upvars'. Do NOT
# use multiple '_upvar' calls, since one '_upvar' call might
# reassign a variable to be used by another '_upvar' call.
# See: http://fvue.nl/wiki/Bash:_Passing_variables_by_reference
_upvar() {
if unset -v "$1"; then # Unset & validate varname
if (( $# == 2 )); then
eval $1=\"\$2\" # Return single value
else
eval $1=\(\"\${@:2}\"\) # Return array
fi
fi
}
# Assign variables one scope above the caller
# Usage: local varname [varname ...] &&
# _upvars [-v varname value] | [-aN varname [value ...]] ...
# Available OPTIONS:
# -aN Assign next N values to varname as array
# -v Assign single value to varname
# Return: 1 if error occurs
# See: http://fvue.nl/wiki/Bash:_Passing_variables_by_reference
_upvars() {
if ! (( $# )); then
echo "${FUNCNAME[0]}: usage: ${FUNCNAME[0]} [-v varname"\
"value] | [-aN varname [value ...]] ..." 1>&2
return 2
fi
while (( $# )); do
case $1 in
-a*)
# Error checking
[[ ${1#-a} ]] || { echo "bash: ${FUNCNAME[0]}: \`$1': missing"\
"number specifier" 1>&2; return 1; }
printf %d "${1#-a}" &> /dev/null || { echo "bash:"\
"${FUNCNAME[0]}: \`$1': invalid number specifier" 1>&2
return 1; }
# Assign array of -aN elements
[[ "$2" ]] && unset -v "$2" && eval $2=\(\"\${@:3:${1#-a}}\"\) &&
shift $((${1#-a} + 2)) || { echo "bash: ${FUNCNAME[0]}:"\
"\`$1${2+ }$2': missing argument(s)" 1>&2; return 1; }
;;
-v)
# Assign single value
[[ "$2" ]] && unset -v "$2" && eval $2=\"\$3\" &&
shift 3 || { echo "bash: ${FUNCNAME[0]}: $1: missing"\
"argument(s)" 1>&2; return 1; }
;;
*)
echo "bash: ${FUNCNAME[0]}: $1: invalid option" 1>&2
return 1 ;;
esac
done
}
# Reassemble command line words, excluding specified characters from the
# list of word completion separators (COMP_WORDBREAKS).
# @param $1 chars Characters out of $COMP_WORDBREAKS which should
# NOT be considered word breaks. This is useful for things like scp where
# we want to return host:path and not only path, so we would pass the
# colon (:) as $1 here.
# @param $2 words Name of variable to return words to
# @param $3 cword Name of variable to return cword to
#
__reassemble_comp_words_by_ref() {
local exclude i j ref
# Exclude word separator characters?
if [[ $1 ]]; then
# Yes, exclude word separator characters;
# Exclude only those characters, which were really included
exclude="${1//[^$COMP_WORDBREAKS]}"
fi
# Default to cword unchanged
eval $3=$COMP_CWORD
# Are characters excluded which were former included?
if [[ $exclude ]]; then
# Yes, list of word completion separators has shrunk;
# Re-assemble words to complete
for (( i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
# Is current word not word 0 (the command itself) and is word not
# empty and is word made up of just word separator characters to be
# excluded?
while [[ $i -gt 0 && ${COMP_WORDS[$i]} &&
${COMP_WORDS[$i]//[^$exclude]} == ${COMP_WORDS[$i]}
]]; do
[ $j -ge 2 ] && ((j--))
# Append word separator to current word
ref="$2[$j]"
eval $2[$j]=\${!ref}\${COMP_WORDS[i]}
# Indicate new cword
[ $i = $COMP_CWORD ] && eval $3=$j
# Indicate next word if available, else end *both* while and for loop
(( $i < ${#COMP_WORDS[@]} - 1)) && ((i++)) || break 2
done
# Append word to current word
ref="$2[$j]"
eval $2[$j]=\${!ref}\${COMP_WORDS[i]}
# Indicate new cword
[[ $i == $COMP_CWORD ]] && eval $3=$j
done
else
# No, list of word completions separators hasn't changed;
eval $2=\( \"\${COMP_WORDS[@]}\" \)
fi
} # __reassemble_comp_words_by_ref()
# @param $1 exclude Characters out of $COMP_WORDBREAKS which should NOT be
# considered word breaks. This is useful for things like scp where
# we want to return host:path and not only path, so we would pass the
# colon (:) as $1 in this case. Bash-3 doesn't do word splitting, so this
# ensures we get the same word on both bash-3 and bash-4.
# @param $2 words Name of variable to return words to
# @param $3 cword Name of variable to return cword to
# @param $4 cur Name of variable to return current word to complete to
# @see ___get_cword_at_cursor_by_ref()
__get_cword_at_cursor_by_ref() {
local cword words=()
__reassemble_comp_words_by_ref "$1" words cword
local i cur2
local cur="$COMP_LINE"
local index="$COMP_POINT"
for (( i = 0; i <= cword; ++i )); do
while [[
# Current word fits in $cur?
"${#cur}" -ge ${#words[i]} &&
# $cur doesn't match cword?
"${cur:0:${#words[i]}}" != "${words[i]}"
]]; do
# Strip first character
cur="${cur:1}"
# Decrease cursor position
((index--))
done
# Does found word matches cword?
if [[ "$i" -lt "$cword" ]]; then
# No, cword lies further;
local old_size="${#cur}"
cur="${cur#${words[i]}}"
local new_size="${#cur}"
index=$(( index - old_size + new_size ))
fi
done
if [[ "${words[cword]:0:${#cur}}" != "$cur" ]]; then
# We messed up. At least return the whole word so things keep working
cur2=${words[cword]}
else
cur2=${cur:0:$index}
fi
local "$2" "$3" "$4" &&
_upvars -a${#words[@]} $2 "${words[@]}" -v $3 "$cword" -v $4 "$cur2"
}
# Get the word to complete and optional previous words.
# This is nicer than ${COMP_WORDS[$COMP_CWORD]}, since it handles cases
# where the user is completing in the middle of a word.
# (For example, if the line is "ls foobar",
# and the cursor is here --------> ^
# Also one is able to cross over possible wordbreak characters.
# Usage: _get_comp_words_by_ref [OPTIONS] [VARNAMES]
# Available VARNAMES:
# cur Return cur via $cur
# prev Return prev via $prev
# words Return words via $words
# cword Return cword via $cword
#
# Available OPTIONS:
# -n EXCLUDE Characters out of $COMP_WORDBREAKS which should NOT be
# considered word breaks. This is useful for things like scp
# where we want to return host:path and not only path, so we
# would pass the colon (:) as -n option in this case. Bash-3
# doesn't do word splitting, so this ensures we get the same
# word on both bash-3 and bash-4.
# -c VARNAME Return cur via $VARNAME
# -p VARNAME Return prev via $VARNAME
# -w VARNAME Return words via $VARNAME
# -i VARNAME Return cword via $VARNAME
#
# Example usage:
#
# $ _get_comp_words_by_ref -n : cur prev
#
_get_comp_words_by_ref()
{
local exclude flag i OPTIND=1
local cur cword words=()
local upargs=() upvars=() vcur vcword vprev vwords
while getopts "c:i:n:p:w:" flag "$@"; do
case $flag in
c) vcur=$OPTARG ;;
i) vcword=$OPTARG ;;
n) exclude=$OPTARG ;;
p) vprev=$OPTARG ;;
w) vwords=$OPTARG ;;
esac
done
while [[ $# -ge $OPTIND ]]; do
case ${!OPTIND} in
cur) vcur=cur ;;
prev) vprev=prev ;;
cword) vcword=cword ;;
words) vwords=words ;;
*) echo "bash: $FUNCNAME(): \`${!OPTIND}': unknown argument" \
1>&2; return 1
esac
let "OPTIND += 1"
done
__get_cword_at_cursor_by_ref "$exclude" words cword cur
[[ $vcur ]] && { upvars+=("$vcur" ); upargs+=(-v $vcur "$cur" ); }
[[ $vcword ]] && { upvars+=("$vcword"); upargs+=(-v $vcword "$cword"); }
[[ $vprev ]] && { upvars+=("$vprev" ); upargs+=(-v $vprev
"${words[cword - 1]}"); }
[[ $vwords ]] && { upvars+=("$vwords"); upargs+=(-a${#words[@]} $vwords
"${words[@]}"); }
(( ${#upvars[@]} )) && local "${upvars[@]}" && _upvars "${upargs[@]}"
}
_init_completion()
{
_get_comp_words_by_ref $@
}
fi # Bash Completion Check
# Generate completion reply
# Accepts 1 to 4 arguments:
# 1. Space separated string of possible completion words
# 2. A prefix to be added to each possible completion word
# 3. Generate possible completion matches for this word
# 4. A suffix to be added to each possible completion word. Can be used to prevent completing a single result
__p4_complete() {
local IFS=$' \t\n' cur_="${3-$cur}"
[[ $cur_ == *:* ]] && cur_="${cur#*:}"
COMPREPLY=( $(compgen -P "${2-}" -W "$1" -S "${4-}" -- "$cur_") )
}
__p4_filenames() {
COMPREPLY=( $(compgen -f ${cur}) )
}
__p4_directories() {
COMPREPLY=( $(compgen -d ${cur}) )
}
# Generate completion reply for files with revisions.
# e.g. file@label or file#revision
__p4_compfilerev() {
type compopt &>/dev/null && compopt -o nospace
local file prefix cur_="$cur"
case "$cur_" in
*\#*)
file="${cur_%%#*}"
prefix="$file#"
cur_="${cur_#*#}"
__p4_complete "$(__p4_filelog_revs "$file") have head none" "$prefix" "$cur_"
;;
*@*)
if ! shopt -q hostcomplete; then
# Disable file@label completion if the user has enabled hostcomplete.
# hostcomplete is disabled by default for those that have bash-completion installed,
# but for those that don't, hostcomplete will do weird things if we try to
# complete words with an @ symbol.
# To disable hostcomplete, run `shopt -u hostcomplete`
prefix="${cur_%%?(\\)@*}@"
cur_="${cur_#*@}"
__p4_complete "$(__p4_labels "$cur_") now" "$prefix" "$cur_"
fi
;;
*)
local files=( $(compgen -f "$cur_") )
if [ ${#files[@]} -eq 1 ]; then
if ! shopt -q hostcomplete; then
# Only suggest @ and # as a completion if the user has disabled hostcomplete.
__p4_complete "# @" "$files" ""
fi
fi
;;
esac
}
# Generate completion reply for flagged options, like -d which can add more than one flag to an
# option, e.g. p4 diff -dub
# 1. Space separated string of possible completion flags
# 2. A prefix of the existing flags to be added to each possible completion word (e.g. -dub)
__p4_compflags() {
__p4_complete "${1//[${2-$cur}]/}" "${2-$cur}" ""
}
__p4_g_opts="-b -c -C -d -H -I -G -L -p -P -q -r -s -Q -u -x -z"
__p4_cmds="add annotate attribute branch branches change changes changelist changelists clean client clients copy counter counters cstat delete depot depots describe diff diff2 dirs edit filelog files fix fixes flush fstat grep group groups have help info integrate integrated interchanges istat job jobs key keys label labels labelsync list lock logger login logout merge move opened passwd populate print protect protects prune rec reconcile rename reopen resolve resolved revert review reviews set shelve status sizes stream streams submit sync tag tickets unlock unshelve update user users where workspace workspaces"
__p4_filetypes="text binary symlink apple resource unicode utf8 utf16"
__p4_streamtypes="mainline virtual development release task"
__p4_submitopts="submitunchanged submitunchanged+reopen revertunchanged revertunchanged+reopen leaveunchanged leaveunchanged+reopen"
__p4_change_status="pending shelved submitted"
__p4_charsets="auto none eucjp iso8859-1 iso8859-5 iso8859-7 iso8859-15 macosroman shiftjis koi8-r utf8 utf8-bom utf16 and utf16-nobom without utf16le utf16le-bom utf16be utf16be-bom utf32 and utf32-nobom without utf32le utf32le-bom utf32be utf32be-bom cp850 cp858 cp936 cp949 cp950 cp1251 winansi cp1253"
__p4_help_keywords="simple commands charset environment filetypes jobview revisions usage views"
# Takes one argument
# 1: The Perforce environment variable to return
__p4_var() {
echo $(command p4 set $1 | awk '{split($1,a,"="); print a[2]}')
}
__p4_vars() {
echo $(command p4 set | awk -F'=' '{print $1}')
}
__p4_find_cmd() {
for word in ${words[@]:1}; do
if [ ${word:0:1} != "-" ]; then
for p4cmd in ${__p4_cmds}; do
if [ "$word" == "$p4cmd" ]; then
echo $p4cmd
return
fi
done
fi
done
}
# Takes one argument
# 1: option to look for
__p4_find_val() {
local cmd=$(__p4_find_cmd)
local opts=0
for i in ${!words[@]}; do
if [[ "$opts" -eq 1 ]]; then
if [ "${words[$i]}" == "$1" ]; then
echo "${words[(($i+1))]}"
return
fi
elif [ "${words[$i]}" == "$cmd" ]; then
opts=1
fi
done
}
# Takes one argument
# 1: Status of the changes
__p4_changes() {
local changes="command p4 changes -m 10 "
[ -n "$1" ] && changes="$changes -s $1 "
[ -n "$p4client" ] && changes="$changes -c $p4client "
[ -n "$p4user" ] && changes="$changes -u $p4user "
echo $($changes | awk '{print $2}')
}
__p4_mychanges() {
local client=$(__p4_var P4CLIENT)
local user=$(__p4_var P4USER)
local changes="command p4 changes -m 10 "
[ -n "$1" ] && changes="$changes -s $1 "
echo $($changes -c $client -u $user | awk '{print $2}')
}
__p4_filelog_revs() {
local revs=$(command p4 filelog -m 10 $1 | awk '/^... #[0-9]/ {print $2}')
echo "${revs//\#/}"
}
__p4_users() {
echo $(command p4 users | awk '{print $1}')
}
__p4_clients() {
local clients="command p4 clients -m 10 "
[ -n "${1-$cur}" ] && clients="$clients -e ${1-$cur}* "
[ -n "$p4user" ] && clients="$clients -u $p4user "
[ -n "$p4stream" ] && clients="$clients -S $p4stream "
echo $($clients | awk '{print $2}')
}
__p4_branches() {
local branches="command p4 branches -m 10 "
[ -n "${1-$cur}" ] && branches="$branches -e ${1-$cur}* "
[ -n "$p4user" ] && branches="$branches -u $p4user "
echo $($branches | awk '{print $2}')
}
__p4_counters() {
echo $(command p4 counters -m 10 | awk '{print $1}')
}
__p4_depots() {
echo $(command p4 depots | awk '{print $2}')
}
__p4_groups() {
echo $(command p4 groups | awk '{print $2}')
}
__p4_labels() {
local labels="command p4 labels -m 10 "
[ -n "${1-$cur}" ] && labels="$labels -e ${1-$cur}* "
[ -n "$p4user" ] && labels="$labels -u $p4user "
echo $($labels | awk '{print $2}')
}
__p4_streams() {
echo $(command p4 streams -m 10 | awk '{print $1}')
}
__p4_jobs() {
echo $(command p4 jobs -m 10 | awk '{print $1}')
}
__p4_keys() {
echo $(command p4 keys -m 10 | awk '{print $1}')
}
## Below are mappings to Perforce commands
# add -- Open a new file to add it to the depot
#
# p4 add [-c changelist#] [-d -f -I -n] [-t filetype] file ...
_p4_add() {
case "$prev" in
-c)
__p4_complete "$(__p4_mychanges pending)"
return ;;
-t)
__p4_complete "$__p4_filetypes"
return ;;
esac
case "$cur" in
-*)
__p4_complete "-c -d -f -I -n -t"
;;
*)
__p4_filenames
;;
esac
}
# annotate -- Print file lines and their revisions
#
# p4 annotate [-aciIqtu -d<flags>] file[revRange] ...
_p4_annotate() {
case "$cur" in
-d*)
__p4_compflags "b w l"
;;
-*)
__p4_complete "-a -c -i -I -q -t -d"
;;
*)
__p4_compfilerev
;;
esac
}
# attribute -- Set per-revision attributes on revisions
#
# p4 attribute [-e -f -p] -n name [-v value] files...
# p4 attribute [-e -f -p] -i -n name file
_p4_attribute() {
case "$cur" in
-*)
__p4_complete "-e -f -p -i -n -v"
;;
*)
__p4_filenames
;;
esac
}
# branch -- Create, modify, or delete a branch view specification
#
# p4 branch [-f] name
# p4 branch -d [-f] name
# p4 branch [ -S stream ] [ -P parent ] -o name
# p4 branch -i [-f]
_p4_branch() {
case "$prev" in
-S)
__p4_complete "$(__p4_streams)"
return ;;
esac
case "$cur" in
-*)
__p4_complete "-f -d -S -P -o -i"
;;
*)
__p4_complete "$(__p4_branches)"
;;
esac
}
# branches -- Display list of branch specifications
#
# p4 branches [-t] [-u user] [[-e|-E] nameFilter -m max]
_p4_branches() {
p4user=$(__p4_find_val "-u")
case "$prev" in
-u)
__p4_complete "$(__p4_users)"
return ;;
esac
__p4_complete "-t -u -e -E -m"
}
# change -- Create or edit a changelist description
# changelist -- synonym for 'change'
#
# p4 change [-s] [-f | -u] [[-O|-I] changelist#]
# p4 change -d [-f -s -O] changelist#
# p4 change -o [-s] [-f] [[-O|-I] changelist#]
# p4 change -i [-s] [-f | -u]
# p4 change -t restricted | public [-U user] [-f|-u|-O|-I] changelist#
# p4 change -U user [-t restricted | public] [-f] changelist#
# p4 change -d -f --serverid=X changelist#
_p4_change() {
case "$prev" in
-t)
__p4_complete "restricted public"
return ;;
-U)
__p4_complete "$(__p4_users)"
return ;;
esac
case "$cur" in
-*)
__p4_complete "-s -f -u -O -I -d -o -i -t -U"
;;
*)
__p4_complete "$(__p4_changes)"
esac
}
_p4_changelist() {
_p4_change
}
# changes -- Display list of pending and submitted changelists
# changelists -- synonym for 'changes'
#
# p4 changes [-i -t -l -L -f] [-c client] [ -e changelist# ]
# [-m max] [-s status] [-u user] [file[revRange] ...]
_p4_changes() {
p4client=$(__p4_find_val "-c")
p4user=$(__p4_find_val "-u")
p4chstat=$(__p4_find_val "-s")
case "$prev" in
-c)
__p4_complete "$(__p4_clients)"
return ;;
-e)
__p4_complete "$(__p4_changes $p4chstat)"
return ;;
-s)
__p4_complete "$__p4_change_status"
return ;;
-u)
__p4_complete "$(__p4_users)"
return ;;
esac
case "$cur" in
-*)
__p4_complete "-i -t -l -L -f -c -e -m -s -u"
;;
*)
__p4_compfilerev
esac
}
_p4_changelists() {
_p4_changes
}
# clean -- synonym for 'reconcile -w'
#
# p4 clean [-e -a -d -I -l -n] [file ...]
_p4_clean() {
case "$cur" in
-*)
__p4_complete "-e -a -d -I -l -n"
;;
*)
__p4_filenames
esac
}
# client -- Create or edit a client workspace specification and its view
# workspace -- Synonym for 'client'
#
# p4 client [-f] [-t template] [name]
# p4 client -d [-f [-Fs]] name
# p4 client -o [-t template] [name]
# p4 client -S stream [[-c change] -o] [name]
# p4 client -s [-f] -S stream [name]
# p4 client -s [-f] -t template [name]
# p4 client -i [-f]
# p4 client -d -f --serverid=X [-Fs] name
_p4_client() {
p4stream=$(__p4_find_val "-S")
case "$prev" in
-t)
__p4_complete "$(__p4_clients)"
return ;;
-c)
__p4_complete "$(__p4_changes)"
return ;;
-S)
__p4_complete "$(__p4_streams)"
return ;;
esac
case "$cur" in
-*)
__p4_complete "-f -t -d -Fs -o -S -c -s -i"
;;
*)
__p4_complete "$(__p4_clients)"
;;
esac
}
_p4_workspace() {
_p4_client
}
# clients -- Display list of clients
# workspaces -- synonym for 'clients'
#
# p4 clients [-t] [-u user] [[-e|-E] nameFilter -m max] [-S stream]
# [-a | -s serverID]
# p4 clients -U
_p4_clients() {
case "$prev" in
-u)
__p4_complete "$(__p4_users)"
return ;;
-S)
__p4_complete "$(__p4_streams)"
return ;;
esac
__p4_complete "-t -u -e -E -m -S -a -s -U"
}
_p4_workspaces() {
_p4_clients
}
# copy -- Copy one set of files to another
#
# p4 copy [options] fromFile[rev] toFile
# p4 copy [options] -b branch [-r] [toFile[rev] ...]
# p4 copy [options] -b branch -s fromFile[rev] [toFile ...]
# p4 copy [options] -S stream [-P parent] [-F] [-r] [toFile[rev] ...]
#
# options: -c changelist# -f -n -v -m max -q
_p4_copy() {
p4stream=$(__p4_find_val "-S")
case "$prev" in
-c)
__p4_complete "$(__p4_changes)"
return ;;
-b)
__p4_complete "$(__p4_branches)"
return ;;
-S)
__p4_complete "$(__p4_streams)"
return ;;
esac
case "$cur" in
-*)
__p4_complete "-c -f -n -v -m -q -b -r -s -S -P -F -r"
;;
*)
__p4_compfilerev
;;
esac
}
# counter -- Display, set, or delete a counter
#
# p4 counter name
# p4 counter [-f] name value
# p4 counter [-f] -d name
# p4 counter [-f] -i name
# p4 counter [-f] -m [ pair list ]
_p4_counter() {
case "$cur" in
-*)
__p4_complete "-f -d -i -m"
;;
*)
__p4_complete "$(__p4_counters)"
;;
esac
}
# counters -- Display list of known counters
#
# p4 counters [-e nameFilter -m max]
_p4_counters() {
__p4_complete "-e -m"
}
# cstat -- Dump change/sync status for current client
#
# p4 cstat [files...]
_p4_cstat() {
__p4_filenames
}
# delete -- Open an existing file for deletion from the depot
#
# p4 delete [-c changelist#] [-n -v -k] file ...
_p4_delete() {
case "$prev" in
-c)
__p4_complete "$(__p4_mychanges pending)"
return ;;
esac
case "$cur" in
-*)
__p4_complete "-c -n -k -v"
;;
*)
__p4_filenames
;;
esac
}
# depot -- Create or edit a depot specification
#
# p4 depot [-t type] name
# p4 depot -d [-f] name
# p4 depot -o name
# p4 depot -i
_p4_depot() {
case "$prev" in
-t)
__p4_complete "local remote spec stream unload archive tangent"
return ;;
esac
case "$cur" in
-*)
__p4_complete "-t -d -f -o -i"
;;
*)
__p4_complete "$(__p4_depots)"
;;
esac
}
# depots -- Lists defined depots
#
# p4 depots
_p4_depots() {
type compopt &>/dev/null && compopt +o default
}
# describe -- Display a changelist description
#
# p4 describe [-d<flags> -m -s -S -f -O -I] changelist# ...
_p4_describe() {
case "$cur" in
-d*)
__p4_compflags "n c s u b w l"
;;
-*)
__p4_complete "-d -m -s -S -f -O -I"
;;
*)
__p4_complete "$(__p4_changes)"
;;
esac
}
# diff -- Display diff of client file with depot file
#
# p4 diff [-d<flags> -f -m max -Od -s<flag> -t] [file[rev] ...]
_p4_diff() {
case "$cur" in
-d*)
__p4_compflags "n c s u b w l"
;;
-s*)
__p4_compflags "a b d e l r"
;;
-*)
__p4_complete "-d -f -m -Od -s -t"
;;
*)
__p4_compfilerev
;;
esac
}
# diff2 -- Compare one set of depot files to another
#
# p4 diff2 [options] fromFile[rev] toFile[rev]
# p4 diff2 [options] -b branch [[fromFile[rev]] toFile[rev]]
# p4 diff2 [options] [-S stream] [-P parent] [[fromFile[rev]] toFile[rev]]
#
# options: -d<flags> -Od -q -t -u
_p4_diff2() {
case "$prev" in
-d*)
__p4_compflags "n c s u b w l"
;;
-b)
__p4_complete "$(__p4_branches)"
return ;;
-S)
__p4_complete "$(__p4_streams)"
return ;;
esac
case "$cur" in
-*)
__p4_complete "-d -Od -q -t -u -b -S -P"
;;
*)
__p4_compfilerev
;;
esac
}
# dirs -- List depot subdirectories
#
# p4 dirs [-C -D -H] [-S stream] dir[revRange] ...
_p4_dirs() {
case "$prev" in
-S)
__p4_complete "$(__p4_streams)"
return ;;
esac
case "$cur" in
-*)
__p4_complete "-C -D -H -S"
;;
*)
__p4_compfilerev
;;
esac
}
# edit -- Open an existing file for edit
#
# p4 edit [-c changelist#] [-k -n] [-t filetype] file ...
_p4_edit() {
case "$prev" in
-c)
__p4_complete "$(__p4_mychanges pending)"
return ;;
-t)
__p4_complete "$__p4_filetypes"
return ;;
esac
case "$cur" in
-*)
__p4_complete "-c -k -n -t"
;;
*)
__p4_filenames
;;
esac
}
# filelog -- List revision history of files
#
# p4 filelog [-c changelist# -h -i -l -L -t -m max -p -s] file[revRange] ...
_p4_filelog() {
case "$prev" in
-c)
__p4_complete "$(__p4_changes)"
return ;;
esac
case "$cur" in
-*)
__p4_complete "-c -h -i -l -L -t -m -p -s"
;;
*)
__p4_compfilerev
;;
esac
}
# files -- List files in the depot
#
# p4 files [ -a ] [ -A ] [ -e ] [ -m max ] file[revRange] ...
# p4 files -U unloadfile ...
_p4_files() {
case "$cur" in
-*)
__p4_complete "-a -A -e -m -U"
;;
*)
__p4_compfilerev
;;
esac
}
# fix -- Mark jobs as being fixed by the specified changelist
#
# p4 fix [-d] [-s status] -c changelist# jobName ...
_p4_fix() {
p4chstat=$(__p4_find_val "-s")
case "$prev" in
-s)
__p4_complete "$__p4_change_status"
return ;;
-c)
__p4_complete "$(__p4_changes)"
return ;;
esac
case "$cur" in
-*)
__p4_complete "-d -s -c"
;;
*)
__p4_complete "$(__p4_jobs)"
;;
esac
}
# fixes -- List jobs with fixes and the changelists that fix them
#
# p4 fixes [-i -m max -c changelist# -j jobName] [file[revRange] ...]
_p4_fixes() {