1#
2# bash completion support for core Git.
3#
4# Copyright (C) 2006,2007 Shawn Pearce
5# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
6#
7# The contained completion routines provide support for completing:
8#
9# *) local and remote branch names
10# *) local and remote tag names
11# *) .git/remotes file names
12# *) git 'subcommands'
13# *) tree paths within 'ref:path/to/file' expressions
14#
15# To use these routines:
16#
17# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
18# 2) Added the following line to your .bashrc:
19# source ~/.git-completion.sh
20#
21# 3) You may want to make sure the git executable is available
22# in your PATH before this script is sourced, as some caching
23# is performed while the script loads. If git isn't found
24# at source time then all lookups will be done on demand,
25# which may be slightly slower.
26#
27# 4) Consider changing your PS1 to also show the current branch:
28# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
29#
30# The argument to __git_ps1 will be displayed only if you
31# are currently in a git repository. The %s token will be
32# the name of the current branch.
33#
34
35__gitdir ()
36{
37 if [ -z "$1" ]; then
38 if [ -n "$__git_dir" ]; then
39 echo "$__git_dir"
40 elif [ -d .git ]; then
41 echo .git
42 else
43 git rev-parse --git-dir 2>/dev/null
44 fi
45 elif [ -d "$1/.git" ]; then
46 echo "$1/.git"
47 else
48 echo "$1"
49 fi
50}
51
52__git_ps1 ()
53{
54 local b="$(git symbolic-ref HEAD 2>/dev/null)"
55 if [ -n "$b" ]; then
56 if [ -n "$1" ]; then
57 printf "$1" "${b##refs/heads/}"
58 else
59 printf " (%s)" "${b##refs/heads/}"
60 fi
61 fi
62}
63
64__gitcomp ()
65{
66 local all c s=$'\n' IFS=' '$'\t'$'\n'
67 local cur="${COMP_WORDS[COMP_CWORD]}"
68 if [ $# -gt 2 ]; then
69 cur="$3"
70 fi
71 for c in $1; do
72 case "$c$4" in
73 --*=*) all="$all$c$4$s" ;;
74 *.) all="$all$c$4$s" ;;
75 *) all="$all$c$4 $s" ;;
76 esac
77 done
78 IFS=$s
79 COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
80 return
81}
82
83__git_heads ()
84{
85 local cmd i is_hash=y dir="$(__gitdir "$1")"
86 if [ -d "$dir" ]; then
87 for i in $(git --git-dir="$dir" \
88 for-each-ref --format='%(refname)' \
89 refs/heads ); do
90 echo "${i#refs/heads/}"
91 done
92 return
93 fi
94 for i in $(git-ls-remote "$1" 2>/dev/null); do
95 case "$is_hash,$i" in
96 y,*) is_hash=n ;;
97 n,*^{}) is_hash=y ;;
98 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
99 n,*) is_hash=y; echo "$i" ;;
100 esac
101 done
102}
103
104__git_refs ()
105{
106 local cmd i is_hash=y dir="$(__gitdir "$1")"
107 if [ -d "$dir" ]; then
108 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
109 for i in $(git --git-dir="$dir" \
110 for-each-ref --format='%(refname)' \
111 refs/tags refs/heads refs/remotes); do
112 case "$i" in
113 refs/tags/*) echo "${i#refs/tags/}" ;;
114 refs/heads/*) echo "${i#refs/heads/}" ;;
115 refs/remotes/*) echo "${i#refs/remotes/}" ;;
116 *) echo "$i" ;;
117 esac
118 done
119 return
120 fi
121 for i in $(git-ls-remote "$dir" 2>/dev/null); do
122 case "$is_hash,$i" in
123 y,*) is_hash=n ;;
124 n,*^{}) is_hash=y ;;
125 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
126 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
127 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
128 n,*) is_hash=y; echo "$i" ;;
129 esac
130 done
131}
132
133__git_refs2 ()
134{
135 local i
136 for i in $(__git_refs "$1"); do
137 echo "$i:$i"
138 done
139}
140
141__git_refs_remotes ()
142{
143 local cmd i is_hash=y
144 for i in $(git-ls-remote "$1" 2>/dev/null); do
145 case "$is_hash,$i" in
146 n,refs/heads/*)
147 is_hash=y
148 echo "$i:refs/remotes/$1/${i#refs/heads/}"
149 ;;
150 y,*) is_hash=n ;;
151 n,*^{}) is_hash=y ;;
152 n,refs/tags/*) is_hash=y;;
153 n,*) is_hash=y; ;;
154 esac
155 done
156}
157
158__git_remotes ()
159{
160 local i ngoff IFS=$'\n' d="$(__gitdir)"
161 shopt -q nullglob || ngoff=1
162 shopt -s nullglob
163 for i in "$d/remotes"/*; do
164 echo ${i#$d/remotes/}
165 done
166 [ "$ngoff" ] && shopt -u nullglob
167 for i in $(git --git-dir="$d" config --list); do
168 case "$i" in
169 remote.*.url=*)
170 i="${i#remote.}"
171 echo "${i/.url=*/}"
172 ;;
173 esac
174 done
175}
176
177__git_merge_strategies ()
178{
179 if [ -n "$__git_merge_strategylist" ]; then
180 echo "$__git_merge_strategylist"
181 return
182 fi
183 sed -n "/^all_strategies='/{
184 s/^all_strategies='//
185 s/'//
186 p
187 q
188 }" "$(git --exec-path)/git-merge"
189}
190__git_merge_strategylist=
191__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
192
193__git_complete_file ()
194{
195 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
196 case "$cur" in
197 ?*:*)
198 ref="${cur%%:*}"
199 cur="${cur#*:}"
200 case "$cur" in
201 ?*/*)
202 pfx="${cur%/*}"
203 cur="${cur##*/}"
204 ls="$ref:$pfx"
205 pfx="$pfx/"
206 ;;
207 *)
208 ls="$ref"
209 ;;
210 esac
211 COMPREPLY=($(compgen -P "$pfx" \
212 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
213 | sed '/^100... blob /s,^.* ,,
214 /^040000 tree /{
215 s,^.* ,,
216 s,$,/,
217 }
218 s/^.* //')" \
219 -- "$cur"))
220 ;;
221 *)
222 __gitcomp "$(__git_refs)"
223 ;;
224 esac
225}
226
227__git_complete_revlist ()
228{
229 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
230 case "$cur" in
231 *...*)
232 pfx="${cur%...*}..."
233 cur="${cur#*...}"
234 __gitcomp "$(__git_refs)" "$pfx" "$cur"
235 ;;
236 *..*)
237 pfx="${cur%..*}.."
238 cur="${cur#*..}"
239 __gitcomp "$(__git_refs)" "$pfx" "$cur"
240 ;;
241 *.)
242 __gitcomp "$cur."
243 ;;
244 *)
245 __gitcomp "$(__git_refs)"
246 ;;
247 esac
248}
249
250__git_commands ()
251{
252 if [ -n "$__git_commandlist" ]; then
253 echo "$__git_commandlist"
254 return
255 fi
256 local i IFS=" "$'\n'
257 for i in $(git help -a|egrep '^ ')
258 do
259 case $i in
260 add--interactive) : plumbing;;
261 applymbox) : ask gittus;;
262 applypatch) : ask gittus;;
263 archimport) : import;;
264 cat-file) : plumbing;;
265 check-attr) : plumbing;;
266 check-ref-format) : plumbing;;
267 commit-tree) : plumbing;;
268 convert-objects) : plumbing;;
269 cvsexportcommit) : export;;
270 cvsimport) : import;;
271 cvsserver) : daemon;;
272 daemon) : daemon;;
273 diff-files) : plumbing;;
274 diff-index) : plumbing;;
275 diff-tree) : plumbing;;
276 fast-import) : import;;
277 fsck-objects) : plumbing;;
278 fetch--tool) : plumbing;;
279 fetch-pack) : plumbing;;
280 fmt-merge-msg) : plumbing;;
281 for-each-ref) : plumbing;;
282 hash-object) : plumbing;;
283 http-*) : transport;;
284 index-pack) : plumbing;;
285 init-db) : deprecated;;
286 local-fetch) : plumbing;;
287 mailinfo) : plumbing;;
288 mailsplit) : plumbing;;
289 merge-*) : plumbing;;
290 mktree) : plumbing;;
291 mktag) : plumbing;;
292 pack-objects) : plumbing;;
293 pack-redundant) : plumbing;;
294 pack-refs) : plumbing;;
295 parse-remote) : plumbing;;
296 patch-id) : plumbing;;
297 peek-remote) : plumbing;;
298 prune) : plumbing;;
299 prune-packed) : plumbing;;
300 quiltimport) : import;;
301 read-tree) : plumbing;;
302 receive-pack) : plumbing;;
303 reflog) : plumbing;;
304 repo-config) : plumbing;;
305 rerere) : plumbing;;
306 rev-list) : plumbing;;
307 rev-parse) : plumbing;;
308 runstatus) : plumbing;;
309 sh-setup) : internal;;
310 shell) : daemon;;
311 send-pack) : plumbing;;
312 show-index) : plumbing;;
313 ssh-*) : transport;;
314 stripspace) : plumbing;;
315 svn) : import export;;
316 svnimport) : import;;
317 symbolic-ref) : plumbing;;
318 tar-tree) : deprecated;;
319 unpack-file) : plumbing;;
320 unpack-objects) : plumbing;;
321 update-index) : plumbing;;
322 update-ref) : plumbing;;
323 update-server-info) : daemon;;
324 upload-archive) : plumbing;;
325 upload-pack) : plumbing;;
326 write-tree) : plumbing;;
327 verify-tag) : plumbing;;
328 *) echo $i;;
329 esac
330 done
331}
332__git_commandlist=
333__git_commandlist="$(__git_commands 2>/dev/null)"
334
335__git_aliases ()
336{
337 local i IFS=$'\n'
338 for i in $(git --git-dir="$(__gitdir)" config --list); do
339 case "$i" in
340 alias.*)
341 i="${i#alias.}"
342 echo "${i/=*/}"
343 ;;
344 esac
345 done
346}
347
348__git_aliased_command ()
349{
350 local word cmdline=$(git --git-dir="$(__gitdir)" \
351 config --get "alias.$1")
352 for word in $cmdline; do
353 if [ "${word##-*}" ]; then
354 echo $word
355 return
356 fi
357 done
358}
359
360__git_whitespacelist="nowarn warn error error-all strip"
361
362_git_am ()
363{
364 local cur="${COMP_WORDS[COMP_CWORD]}"
365 if [ -d .dotest ]; then
366 __gitcomp "--skip --resolved"
367 return
368 fi
369 case "$cur" in
370 --whitespace=*)
371 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
372 return
373 ;;
374 --*)
375 __gitcomp "
376 --signoff --utf8 --binary --3way --interactive
377 --whitespace=
378 "
379 return
380 esac
381 COMPREPLY=()
382}
383
384_git_apply ()
385{
386 local cur="${COMP_WORDS[COMP_CWORD]}"
387 case "$cur" in
388 --whitespace=*)
389 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
390 return
391 ;;
392 --*)
393 __gitcomp "
394 --stat --numstat --summary --check --index
395 --cached --index-info --reverse --reject --unidiff-zero
396 --apply --no-add --exclude=
397 --whitespace= --inaccurate-eof --verbose
398 "
399 return
400 esac
401 COMPREPLY=()
402}
403
404_git_add ()
405{
406 local cur="${COMP_WORDS[COMP_CWORD]}"
407 case "$cur" in
408 --*)
409 __gitcomp "--interactive"
410 return
411 esac
412 COMPREPLY=()
413}
414
415_git_bisect ()
416{
417 local i c=1 command
418 while [ $c -lt $COMP_CWORD ]; do
419 i="${COMP_WORDS[c]}"
420 case "$i" in
421 start|bad|good|reset|visualize|replay|log)
422 command="$i"
423 break
424 ;;
425 esac
426 c=$((++c))
427 done
428
429 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
430 __gitcomp "start bad good reset visualize replay log"
431 return
432 fi
433
434 case "$command" in
435 bad|good|reset)
436 __gitcomp "$(__git_refs)"
437 ;;
438 *)
439 COMPREPLY=()
440 ;;
441 esac
442}
443
444_git_branch ()
445{
446 __gitcomp "$(__git_refs)"
447}
448
449_git_checkout ()
450{
451 __gitcomp "$(__git_refs)"
452}
453
454_git_cherry ()
455{
456 __gitcomp "$(__git_refs)"
457}
458
459_git_cherry_pick ()
460{
461 local cur="${COMP_WORDS[COMP_CWORD]}"
462 case "$cur" in
463 --*)
464 __gitcomp "--edit --no-commit"
465 ;;
466 *)
467 __gitcomp "$(__git_refs)"
468 ;;
469 esac
470}
471
472_git_commit ()
473{
474 local cur="${COMP_WORDS[COMP_CWORD]}"
475 case "$cur" in
476 --*)
477 __gitcomp "
478 --all --author= --signoff --verify --no-verify
479 --edit --amend --include --only
480 "
481 return
482 esac
483 COMPREPLY=()
484}
485
486_git_diff ()
487{
488 __git_complete_file
489}
490
491_git_diff_tree ()
492{
493 __gitcomp "$(__git_refs)"
494}
495
496_git_fetch ()
497{
498 local cur="${COMP_WORDS[COMP_CWORD]}"
499
500 case "${COMP_WORDS[0]},$COMP_CWORD" in
501 git-fetch*,1)
502 __gitcomp "$(__git_remotes)"
503 ;;
504 git,2)
505 __gitcomp "$(__git_remotes)"
506 ;;
507 *)
508 case "$cur" in
509 *:*)
510 __gitcomp "$(__git_refs)" "" "${cur#*:}"
511 ;;
512 *)
513 local remote
514 case "${COMP_WORDS[0]}" in
515 git-fetch) remote="${COMP_WORDS[1]}" ;;
516 git) remote="${COMP_WORDS[2]}" ;;
517 esac
518 __gitcomp "$(__git_refs2 "$remote")"
519 ;;
520 esac
521 ;;
522 esac
523}
524
525_git_format_patch ()
526{
527 local cur="${COMP_WORDS[COMP_CWORD]}"
528 case "$cur" in
529 --*)
530 __gitcomp "
531 --stdout --attach --thread
532 --output-directory
533 --numbered --start-number
534 --keep-subject
535 --signoff
536 --in-reply-to=
537 --full-index --binary
538 --not --all
539 "
540 return
541 ;;
542 esac
543 __git_complete_revlist
544}
545
546_git_gc ()
547{
548 local cur="${COMP_WORDS[COMP_CWORD]}"
549 case "$cur" in
550 --*)
551 __gitcomp "--prune"
552 return
553 ;;
554 esac
555 COMPREPLY=()
556}
557
558_git_ls_remote ()
559{
560 __gitcomp "$(__git_remotes)"
561}
562
563_git_ls_tree ()
564{
565 __git_complete_file
566}
567
568_git_log ()
569{
570 local cur="${COMP_WORDS[COMP_CWORD]}"
571 case "$cur" in
572 --pretty=*)
573 __gitcomp "
574 oneline short medium full fuller email raw
575 " "" "${cur##--pretty=}"
576 return
577 ;;
578 --*)
579 __gitcomp "
580 --max-count= --max-age= --since= --after=
581 --min-age= --before= --until=
582 --root --not --topo-order --date-order
583 --no-merges
584 --abbrev-commit --abbrev=
585 --relative-date
586 --author= --committer= --grep=
587 --all-match
588 --pretty= --name-status --name-only
589 --not --all
590 "
591 return
592 ;;
593 esac
594 __git_complete_revlist
595}
596
597_git_merge ()
598{
599 local cur="${COMP_WORDS[COMP_CWORD]}"
600 case "${COMP_WORDS[COMP_CWORD-1]}" in
601 -s|--strategy)
602 __gitcomp "$(__git_merge_strategies)"
603 return
604 esac
605 case "$cur" in
606 --strategy=*)
607 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
608 return
609 ;;
610 --*)
611 __gitcomp "
612 --no-commit --no-summary --squash --strategy
613 "
614 return
615 esac
616 __gitcomp "$(__git_refs)"
617}
618
619_git_merge_base ()
620{
621 __gitcomp "$(__git_refs)"
622}
623
624_git_name_rev ()
625{
626 __gitcomp "--tags --all --stdin"
627}
628
629_git_pull ()
630{
631 local cur="${COMP_WORDS[COMP_CWORD]}"
632
633 case "${COMP_WORDS[0]},$COMP_CWORD" in
634 git-pull*,1)
635 __gitcomp "$(__git_remotes)"
636 ;;
637 git,2)
638 __gitcomp "$(__git_remotes)"
639 ;;
640 *)
641 local remote
642 case "${COMP_WORDS[0]}" in
643 git-pull) remote="${COMP_WORDS[1]}" ;;
644 git) remote="${COMP_WORDS[2]}" ;;
645 esac
646 __gitcomp "$(__git_refs "$remote")"
647 ;;
648 esac
649}
650
651_git_push ()
652{
653 local cur="${COMP_WORDS[COMP_CWORD]}"
654
655 case "${COMP_WORDS[0]},$COMP_CWORD" in
656 git-push*,1)
657 __gitcomp "$(__git_remotes)"
658 ;;
659 git,2)
660 __gitcomp "$(__git_remotes)"
661 ;;
662 *)
663 case "$cur" in
664 *:*)
665 local remote
666 case "${COMP_WORDS[0]}" in
667 git-push) remote="${COMP_WORDS[1]}" ;;
668 git) remote="${COMP_WORDS[2]}" ;;
669 esac
670 __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
671 ;;
672 *)
673 __gitcomp "$(__git_refs2)"
674 ;;
675 esac
676 ;;
677 esac
678}
679
680_git_rebase ()
681{
682 local cur="${COMP_WORDS[COMP_CWORD]}"
683 if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
684 __gitcomp "--continue --skip --abort"
685 return
686 fi
687 case "${COMP_WORDS[COMP_CWORD-1]}" in
688 -s|--strategy)
689 __gitcomp "$(__git_merge_strategies)"
690 return
691 esac
692 case "$cur" in
693 --strategy=*)
694 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
695 return
696 ;;
697 --*)
698 __gitcomp "--onto --merge --strategy"
699 return
700 esac
701 __gitcomp "$(__git_refs)"
702}
703
704_git_config ()
705{
706 local cur="${COMP_WORDS[COMP_CWORD]}"
707 local prv="${COMP_WORDS[COMP_CWORD-1]}"
708 case "$prv" in
709 branch.*.remote)
710 __gitcomp "$(__git_remotes)"
711 return
712 ;;
713 branch.*.merge)
714 __gitcomp "$(__git_refs)"
715 return
716 ;;
717 remote.*.fetch)
718 local remote="${prv#remote.}"
719 remote="${remote%.fetch}"
720 __gitcomp "$(__git_refs_remotes "$remote")"
721 return
722 ;;
723 remote.*.push)
724 local remote="${prv#remote.}"
725 remote="${remote%.push}"
726 __gitcomp "$(git --git-dir="$(__gitdir)" \
727 for-each-ref --format='%(refname):%(refname)' \
728 refs/heads)"
729 return
730 ;;
731 pull.twohead|pull.octopus)
732 __gitcomp "$(__git_merge_strategies)"
733 return
734 ;;
735 color.branch|color.diff|color.status)
736 __gitcomp "always never auto"
737 return
738 ;;
739 color.*.*)
740 __gitcomp "
741 black red green yellow blue magenta cyan white
742 bold dim ul blink reverse
743 "
744 return
745 ;;
746 *.*)
747 COMPREPLY=()
748 return
749 ;;
750 esac
751 case "$cur" in
752 --*)
753 __gitcomp "
754 --global --list --replace-all
755 --get --get-all --get-regexp
756 --add --unset --unset-all
757 "
758 return
759 ;;
760 branch.*.*)
761 local pfx="${cur%.*}."
762 cur="${cur##*.}"
763 __gitcomp "remote merge" "$pfx" "$cur"
764 return
765 ;;
766 branch.*)
767 local pfx="${cur%.*}."
768 cur="${cur#*.}"
769 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
770 return
771 ;;
772 remote.*.*)
773 local pfx="${cur%.*}."
774 cur="${cur##*.}"
775 __gitcomp "url fetch push" "$pfx" "$cur"
776 return
777 ;;
778 remote.*)
779 local pfx="${cur%.*}."
780 cur="${cur#*.}"
781 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
782 return
783 ;;
784 esac
785 __gitcomp "
786 apply.whitespace
787 core.fileMode
788 core.gitProxy
789 core.ignoreStat
790 core.preferSymlinkRefs
791 core.logAllRefUpdates
792 core.repositoryFormatVersion
793 core.sharedRepository
794 core.warnAmbiguousRefs
795 core.compression
796 core.legacyHeaders
797 core.packedGitWindowSize
798 core.packedGitLimit
799 clean.requireForce
800 color.branch
801 color.branch.current
802 color.branch.local
803 color.branch.remote
804 color.branch.plain
805 color.diff
806 color.diff.plain
807 color.diff.meta
808 color.diff.frag
809 color.diff.old
810 color.diff.new
811 color.diff.commit
812 color.diff.whitespace
813 color.pager
814 color.status
815 color.status.header
816 color.status.added
817 color.status.changed
818 color.status.untracked
819 diff.renameLimit
820 diff.renames
821 fetch.unpackLimit
822 format.headers
823 gitcvs.enabled
824 gitcvs.logfile
825 gc.reflogexpire
826 gc.reflogexpireunreachable
827 gc.rerereresolved
828 gc.rerereunresolved
829 http.sslVerify
830 http.sslCert
831 http.sslKey
832 http.sslCAInfo
833 http.sslCAPath
834 http.maxRequests
835 http.lowSpeedLimit
836 http.lowSpeedTime
837 http.noEPSV
838 i18n.commitEncoding
839 i18n.logOutputEncoding
840 log.showroot
841 merge.summary
842 merge.verbosity
843 pack.window
844 pull.octopus
845 pull.twohead
846 repack.useDeltaBaseOffset
847 show.difftree
848 showbranch.default
849 tar.umask
850 transfer.unpackLimit
851 receive.unpackLimit
852 receive.denyNonFastForwards
853 user.name
854 user.email
855 user.signingkey
856 whatchanged.difftree
857 branch. remote.
858 "
859}
860
861_git_remote ()
862{
863 local i c=1 command
864 while [ $c -lt $COMP_CWORD ]; do
865 i="${COMP_WORDS[c]}"
866 case "$i" in
867 add|show|prune) command="$i"; break ;;
868 esac
869 c=$((++c))
870 done
871
872 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
873 __gitcomp "add show prune"
874 return
875 fi
876
877 case "$command" in
878 show|prune)
879 __gitcomp "$(__git_remotes)"
880 ;;
881 *)
882 COMPREPLY=()
883 ;;
884 esac
885}
886
887_git_reset ()
888{
889 local cur="${COMP_WORDS[COMP_CWORD]}"
890 case "$cur" in
891 --*)
892 __gitcomp "--mixed --hard --soft"
893 return
894 ;;
895 esac
896 __gitcomp "$(__git_refs)"
897}
898
899_git_shortlog ()
900{
901 local cur="${COMP_WORDS[COMP_CWORD]}"
902 case "$cur" in
903 --*)
904 __gitcomp "
905 --max-count= --max-age= --since= --after=
906 --min-age= --before= --until=
907 --no-merges
908 --author= --committer= --grep=
909 --all-match
910 --not --all
911 --numbered --summary
912 "
913 return
914 ;;
915 esac
916 __git_complete_revlist
917}
918
919_git_show ()
920{
921 local cur="${COMP_WORDS[COMP_CWORD]}"
922 case "$cur" in
923 --pretty=*)
924 __gitcomp "
925 oneline short medium full fuller email raw
926 " "" "${cur##--pretty=}"
927 return
928 ;;
929 --*)
930 __gitcomp "--pretty="
931 return
932 ;;
933 esac
934 __git_complete_file
935}
936
937_git ()
938{
939 local i c=1 command __git_dir
940
941 while [ $c -lt $COMP_CWORD ]; do
942 i="${COMP_WORDS[c]}"
943 case "$i" in
944 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
945 --bare) __git_dir="." ;;
946 --version|--help|-p|--paginate) ;;
947 *) command="$i"; break ;;
948 esac
949 c=$((++c))
950 done
951
952 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
953 case "${COMP_WORDS[COMP_CWORD]}" in
954 --*=*) COMPREPLY=() ;;
955 --*) __gitcomp "--git-dir= --bare --version --exec-path" ;;
956 *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
957 esac
958 return
959 fi
960
961 local expansion=$(__git_aliased_command "$command")
962 [ "$expansion" ] && command="$expansion"
963
964 case "$command" in
965 am) _git_am ;;
966 add) _git_add ;;
967 apply) _git_apply ;;
968 bisect) _git_bisect ;;
969 branch) _git_branch ;;
970 checkout) _git_checkout ;;
971 cherry) _git_cherry ;;
972 cherry-pick) _git_cherry_pick ;;
973 commit) _git_commit ;;
974 config) _git_config ;;
975 diff) _git_diff ;;
976 fetch) _git_fetch ;;
977 format-patch) _git_format_patch ;;
978 gc) _git_gc ;;
979 log) _git_log ;;
980 ls-remote) _git_ls_remote ;;
981 ls-tree) _git_ls_tree ;;
982 merge) _git_merge;;
983 merge-base) _git_merge_base ;;
984 name-rev) _git_name_rev ;;
985 pull) _git_pull ;;
986 push) _git_push ;;
987 rebase) _git_rebase ;;
988 remote) _git_remote ;;
989 reset) _git_reset ;;
990 shortlog) _git_shortlog ;;
991 show) _git_show ;;
992 show-branch) _git_log ;;
993 whatchanged) _git_log ;;
994 *) COMPREPLY=() ;;
995 esac
996}
997
998_gitk ()
999{
1000 local cur="${COMP_WORDS[COMP_CWORD]}"
1001 case "$cur" in
1002 --*)
1003 __gitcomp "--not --all"
1004 return
1005 ;;
1006 esac
1007 __git_complete_revlist
1008}
1009
1010complete -o default -o nospace -F _git git
1011complete -o default -o nospace -F _gitk gitk
1012complete -o default -o nospace -F _git_am git-am
1013complete -o default -o nospace -F _git_apply git-apply
1014complete -o default -o nospace -F _git_bisect git-bisect
1015complete -o default -o nospace -F _git_branch git-branch
1016complete -o default -o nospace -F _git_checkout git-checkout
1017complete -o default -o nospace -F _git_cherry git-cherry
1018complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
1019complete -o default -o nospace -F _git_commit git-commit
1020complete -o default -o nospace -F _git_diff git-diff
1021complete -o default -o nospace -F _git_fetch git-fetch
1022complete -o default -o nospace -F _git_format_patch git-format-patch
1023complete -o default -o nospace -F _git_gc git-gc
1024complete -o default -o nospace -F _git_log git-log
1025complete -o default -o nospace -F _git_ls_remote git-ls-remote
1026complete -o default -o nospace -F _git_ls_tree git-ls-tree
1027complete -o default -o nospace -F _git_merge git-merge
1028complete -o default -o nospace -F _git_merge_base git-merge-base
1029complete -o default -o nospace -F _git_name_rev git-name-rev
1030complete -o default -o nospace -F _git_pull git-pull
1031complete -o default -o nospace -F _git_push git-push
1032complete -o default -o nospace -F _git_rebase git-rebase
1033complete -o default -o nospace -F _git_config git-config
1034complete -o default -o nospace -F _git_remote git-remote
1035complete -o default -o nospace -F _git_reset git-reset
1036complete -o default -o nospace -F _git_shortlog git-shortlog
1037complete -o default -o nospace -F _git_show git-show
1038complete -o default -o nospace -F _git_log git-show-branch
1039complete -o default -o nospace -F _git_log git-whatchanged
1040
1041# The following are necessary only for Cygwin, and only are needed
1042# when the user has tab-completed the executable name and consequently
1043# included the '.exe' suffix.
1044#
1045if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1046complete -o default -o nospace -F _git_add git-add.exe
1047complete -o default -o nospace -F _git_apply git-apply.exe
1048complete -o default -o nospace -F _git git.exe
1049complete -o default -o nospace -F _git_branch git-branch.exe
1050complete -o default -o nospace -F _git_cherry git-cherry.exe
1051complete -o default -o nospace -F _git_diff git-diff.exe
1052complete -o default -o nospace -F _git_format_patch git-format-patch.exe
1053complete -o default -o nospace -F _git_log git-log.exe
1054complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
1055complete -o default -o nospace -F _git_merge_base git-merge-base.exe
1056complete -o default -o nospace -F _git_name_rev git-name-rev.exe
1057complete -o default -o nospace -F _git_push git-push.exe
1058complete -o default -o nospace -F _git_config git-config
1059complete -o default -o nospace -F _git_shortlog git-shortlog.exe
1060complete -o default -o nospace -F _git_show git-show.exe
1061complete -o default -o nospace -F _git_log git-show-branch.exe
1062complete -o default -o nospace -F _git_log git-whatchanged.exe
1063fi