865531a5fd730c27498283ca1cccd420f7dfeecd
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 #
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 }
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 }
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 }
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 }
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 }
133 __git_refs2 ()
134 {
135 local i
136 for i in $(__git_refs "$1"); do
137 echo "$i:$i"
138 done
139 }
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 }
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 }
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)"
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 }
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 }
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-ref-format) : plumbing;;
266 commit-tree) : plumbing;;
267 convert-objects) : plumbing;;
268 cvsexportcommit) : export;;
269 cvsimport) : import;;
270 cvsserver) : daemon;;
271 daemon) : daemon;;
272 diff-stages) : nobody uses it;;
273 fast-import) : import;;
274 fsck-objects) : plumbing;;
275 fetch-pack) : plumbing;;
276 fmt-merge-msg) : plumbing;;
277 hash-object) : plumbing;;
278 http-*) : transport;;
279 index-pack) : plumbing;;
280 init-db) : deprecated;;
281 local-fetch) : plumbing;;
282 mailinfo) : plumbing;;
283 mailsplit) : plumbing;;
284 merge-*) : plumbing;;
285 mktree) : plumbing;;
286 mktag) : plumbing;;
287 pack-objects) : plumbing;;
288 pack-redundant) : plumbing;;
289 pack-refs) : plumbing;;
290 parse-remote) : plumbing;;
291 patch-id) : plumbing;;
292 peek-remote) : plumbing;;
293 prune) : plumbing;;
294 prune-packed) : plumbing;;
295 quiltimport) : import;;
296 read-tree) : plumbing;;
297 receive-pack) : plumbing;;
298 reflog) : plumbing;;
299 repo-config) : plumbing;;
300 rerere) : plumbing;;
301 rev-list) : plumbing;;
302 rev-parse) : plumbing;;
303 runstatus) : plumbing;;
304 sh-setup) : internal;;
305 shell) : daemon;;
306 send-pack) : plumbing;;
307 show-index) : plumbing;;
308 ssh-*) : transport;;
309 stripspace) : plumbing;;
310 svn) : import export;;
311 svnimport) : import;;
312 symbolic-ref) : plumbing;;
313 tar-tree) : deprecated;;
314 unpack-file) : plumbing;;
315 unpack-objects) : plumbing;;
316 update-index) : plumbing;;
317 update-ref) : plumbing;;
318 update-server-info) : daemon;;
319 upload-archive) : plumbing;;
320 upload-pack) : plumbing;;
321 write-tree) : plumbing;;
322 verify-tag) : plumbing;;
323 *) echo $i;;
324 esac
325 done
326 }
327 __git_commandlist=
328 __git_commandlist="$(__git_commands 2>/dev/null)"
330 __git_aliases ()
331 {
332 local i IFS=$'\n'
333 for i in $(git --git-dir="$(__gitdir)" config --list); do
334 case "$i" in
335 alias.*)
336 i="${i#alias.}"
337 echo "${i/=*/}"
338 ;;
339 esac
340 done
341 }
343 __git_aliased_command ()
344 {
345 local word cmdline=$(git --git-dir="$(__gitdir)" \
346 config --get "alias.$1")
347 for word in $cmdline; do
348 if [ "${word##-*}" ]; then
349 echo $word
350 return
351 fi
352 done
353 }
355 __git_whitespacelist="nowarn warn error error-all strip"
357 _git_am ()
358 {
359 local cur="${COMP_WORDS[COMP_CWORD]}"
360 if [ -d .dotest ]; then
361 __gitcomp "--skip --resolved"
362 return
363 fi
364 case "$cur" in
365 --whitespace=*)
366 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
367 return
368 ;;
369 --*)
370 __gitcomp "
371 --signoff --utf8 --binary --3way --interactive
372 --whitespace=
373 "
374 return
375 esac
376 COMPREPLY=()
377 }
379 _git_apply ()
380 {
381 local cur="${COMP_WORDS[COMP_CWORD]}"
382 case "$cur" in
383 --whitespace=*)
384 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
385 return
386 ;;
387 --*)
388 __gitcomp "
389 --stat --numstat --summary --check --index
390 --cached --index-info --reverse --reject --unidiff-zero
391 --apply --no-add --exclude=
392 --whitespace= --inaccurate-eof --verbose
393 "
394 return
395 esac
396 COMPREPLY=()
397 }
399 _git_add ()
400 {
401 local cur="${COMP_WORDS[COMP_CWORD]}"
402 case "$cur" in
403 --*)
404 __gitcomp "--interactive"
405 return
406 esac
407 COMPREPLY=()
408 }
410 _git_bisect ()
411 {
412 local i c=1 command
413 while [ $c -lt $COMP_CWORD ]; do
414 i="${COMP_WORDS[c]}"
415 case "$i" in
416 start|bad|good|reset|visualize|replay|log)
417 command="$i"
418 break
419 ;;
420 esac
421 c=$((++c))
422 done
424 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
425 __gitcomp "start bad good reset visualize replay log"
426 return
427 fi
429 case "$command" in
430 bad|good|reset)
431 __gitcomp "$(__git_refs)"
432 ;;
433 *)
434 COMPREPLY=()
435 ;;
436 esac
437 }
439 _git_branch ()
440 {
441 __gitcomp "$(__git_refs)"
442 }
444 _git_checkout ()
445 {
446 __gitcomp "$(__git_refs)"
447 }
449 _git_cherry ()
450 {
451 __gitcomp "$(__git_refs)"
452 }
454 _git_cherry_pick ()
455 {
456 local cur="${COMP_WORDS[COMP_CWORD]}"
457 case "$cur" in
458 --*)
459 __gitcomp "--edit --no-commit"
460 ;;
461 *)
462 __gitcomp "$(__git_refs)"
463 ;;
464 esac
465 }
467 _git_commit ()
468 {
469 local cur="${COMP_WORDS[COMP_CWORD]}"
470 case "$cur" in
471 --*)
472 __gitcomp "
473 --all --author= --signoff --verify --no-verify
474 --edit --amend --include --only
475 "
476 return
477 esac
478 COMPREPLY=()
479 }
481 _git_diff ()
482 {
483 __git_complete_file
484 }
486 _git_diff_tree ()
487 {
488 __gitcomp "$(__git_refs)"
489 }
491 _git_fetch ()
492 {
493 local cur="${COMP_WORDS[COMP_CWORD]}"
495 case "${COMP_WORDS[0]},$COMP_CWORD" in
496 git-fetch*,1)
497 __gitcomp "$(__git_remotes)"
498 ;;
499 git,2)
500 __gitcomp "$(__git_remotes)"
501 ;;
502 *)
503 case "$cur" in
504 *:*)
505 __gitcomp "$(__git_refs)" "" "${cur#*:}"
506 ;;
507 *)
508 local remote
509 case "${COMP_WORDS[0]}" in
510 git-fetch) remote="${COMP_WORDS[1]}" ;;
511 git) remote="${COMP_WORDS[2]}" ;;
512 esac
513 __gitcomp "$(__git_refs2 "$remote")"
514 ;;
515 esac
516 ;;
517 esac
518 }
520 _git_format_patch ()
521 {
522 local cur="${COMP_WORDS[COMP_CWORD]}"
523 case "$cur" in
524 --*)
525 __gitcomp "
526 --stdout --attach --thread
527 --output-directory
528 --numbered --start-number
529 --keep-subject
530 --signoff
531 --in-reply-to=
532 --full-index --binary
533 --not --all
534 "
535 return
536 ;;
537 esac
538 __git_complete_revlist
539 }
541 _git_gc ()
542 {
543 local cur="${COMP_WORDS[COMP_CWORD]}"
544 case "$cur" in
545 --*)
546 __gitcomp "--prune"
547 return
548 ;;
549 esac
550 COMPREPLY=()
551 }
553 _git_ls_remote ()
554 {
555 __gitcomp "$(__git_remotes)"
556 }
558 _git_ls_tree ()
559 {
560 __git_complete_file
561 }
563 _git_log ()
564 {
565 local cur="${COMP_WORDS[COMP_CWORD]}"
566 case "$cur" in
567 --pretty=*)
568 __gitcomp "
569 oneline short medium full fuller email raw
570 " "" "${cur##--pretty=}"
571 return
572 ;;
573 --*)
574 __gitcomp "
575 --max-count= --max-age= --since= --after=
576 --min-age= --before= --until=
577 --root --not --topo-order --date-order
578 --no-merges
579 --abbrev-commit --abbrev=
580 --relative-date
581 --author= --committer= --grep=
582 --all-match
583 --pretty= --name-status --name-only
584 --not --all
585 "
586 return
587 ;;
588 esac
589 __git_complete_revlist
590 }
592 _git_merge ()
593 {
594 local cur="${COMP_WORDS[COMP_CWORD]}"
595 case "${COMP_WORDS[COMP_CWORD-1]}" in
596 -s|--strategy)
597 __gitcomp "$(__git_merge_strategies)"
598 return
599 esac
600 case "$cur" in
601 --strategy=*)
602 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
603 return
604 ;;
605 --*)
606 __gitcomp "
607 --no-commit --no-summary --squash --strategy
608 "
609 return
610 esac
611 __gitcomp "$(__git_refs)"
612 }
614 _git_merge_base ()
615 {
616 __gitcomp "$(__git_refs)"
617 }
619 _git_name_rev ()
620 {
621 __gitcomp "--tags --all --stdin"
622 }
624 _git_pull ()
625 {
626 local cur="${COMP_WORDS[COMP_CWORD]}"
628 case "${COMP_WORDS[0]},$COMP_CWORD" in
629 git-pull*,1)
630 __gitcomp "$(__git_remotes)"
631 ;;
632 git,2)
633 __gitcomp "$(__git_remotes)"
634 ;;
635 *)
636 local remote
637 case "${COMP_WORDS[0]}" in
638 git-pull) remote="${COMP_WORDS[1]}" ;;
639 git) remote="${COMP_WORDS[2]}" ;;
640 esac
641 __gitcomp "$(__git_refs "$remote")"
642 ;;
643 esac
644 }
646 _git_push ()
647 {
648 local cur="${COMP_WORDS[COMP_CWORD]}"
650 case "${COMP_WORDS[0]},$COMP_CWORD" in
651 git-push*,1)
652 __gitcomp "$(__git_remotes)"
653 ;;
654 git,2)
655 __gitcomp "$(__git_remotes)"
656 ;;
657 *)
658 case "$cur" in
659 *:*)
660 local remote
661 case "${COMP_WORDS[0]}" in
662 git-push) remote="${COMP_WORDS[1]}" ;;
663 git) remote="${COMP_WORDS[2]}" ;;
664 esac
665 __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
666 ;;
667 *)
668 __gitcomp "$(__git_refs2)"
669 ;;
670 esac
671 ;;
672 esac
673 }
675 _git_rebase ()
676 {
677 local cur="${COMP_WORDS[COMP_CWORD]}"
678 if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
679 __gitcomp "--continue --skip --abort"
680 return
681 fi
682 case "${COMP_WORDS[COMP_CWORD-1]}" in
683 -s|--strategy)
684 __gitcomp "$(__git_merge_strategies)"
685 return
686 esac
687 case "$cur" in
688 --strategy=*)
689 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
690 return
691 ;;
692 --*)
693 __gitcomp "--onto --merge --strategy"
694 return
695 esac
696 __gitcomp "$(__git_refs)"
697 }
699 _git_config ()
700 {
701 local cur="${COMP_WORDS[COMP_CWORD]}"
702 local prv="${COMP_WORDS[COMP_CWORD-1]}"
703 case "$prv" in
704 branch.*.remote)
705 __gitcomp "$(__git_remotes)"
706 return
707 ;;
708 branch.*.merge)
709 __gitcomp "$(__git_refs)"
710 return
711 ;;
712 remote.*.fetch)
713 local remote="${prv#remote.}"
714 remote="${remote%.fetch}"
715 __gitcomp "$(__git_refs_remotes "$remote")"
716 return
717 ;;
718 remote.*.push)
719 local remote="${prv#remote.}"
720 remote="${remote%.push}"
721 __gitcomp "$(git --git-dir="$(__gitdir)" \
722 for-each-ref --format='%(refname):%(refname)' \
723 refs/heads)"
724 return
725 ;;
726 pull.twohead|pull.octopus)
727 __gitcomp "$(__git_merge_strategies)"
728 return
729 ;;
730 color.branch|color.diff|color.status)
731 __gitcomp "always never auto"
732 return
733 ;;
734 color.*.*)
735 __gitcomp "
736 black red green yellow blue magenta cyan white
737 bold dim ul blink reverse
738 "
739 return
740 ;;
741 *.*)
742 COMPREPLY=()
743 return
744 ;;
745 esac
746 case "$cur" in
747 --*)
748 __gitcomp "
749 --global --list --replace-all
750 --get --get-all --get-regexp
751 --add --unset --unset-all
752 "
753 return
754 ;;
755 branch.*.*)
756 local pfx="${cur%.*}."
757 cur="${cur##*.}"
758 __gitcomp "remote merge" "$pfx" "$cur"
759 return
760 ;;
761 branch.*)
762 local pfx="${cur%.*}."
763 cur="${cur#*.}"
764 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
765 return
766 ;;
767 remote.*.*)
768 local pfx="${cur%.*}."
769 cur="${cur##*.}"
770 __gitcomp "url fetch push" "$pfx" "$cur"
771 return
772 ;;
773 remote.*)
774 local pfx="${cur%.*}."
775 cur="${cur#*.}"
776 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
777 return
778 ;;
779 esac
780 __gitcomp "
781 apply.whitespace
782 core.fileMode
783 core.gitProxy
784 core.ignoreStat
785 core.preferSymlinkRefs
786 core.logAllRefUpdates
787 core.repositoryFormatVersion
788 core.sharedRepository
789 core.warnAmbiguousRefs
790 core.compression
791 core.legacyHeaders
792 core.packedGitWindowSize
793 core.packedGitLimit
794 color.branch
795 color.branch.current
796 color.branch.local
797 color.branch.remote
798 color.branch.plain
799 color.diff
800 color.diff.plain
801 color.diff.meta
802 color.diff.frag
803 color.diff.old
804 color.diff.new
805 color.diff.commit
806 color.diff.whitespace
807 color.pager
808 color.status
809 color.status.header
810 color.status.added
811 color.status.changed
812 color.status.untracked
813 diff.renameLimit
814 diff.renames
815 fetch.unpackLimit
816 format.headers
817 gitcvs.enabled
818 gitcvs.logfile
819 gc.reflogexpire
820 gc.reflogexpireunreachable
821 gc.rerereresolved
822 gc.rerereunresolved
823 http.sslVerify
824 http.sslCert
825 http.sslKey
826 http.sslCAInfo
827 http.sslCAPath
828 http.maxRequests
829 http.lowSpeedLimit
830 http.lowSpeedTime
831 http.noEPSV
832 i18n.commitEncoding
833 i18n.logOutputEncoding
834 log.showroot
835 merge.summary
836 merge.verbosity
837 pack.window
838 pull.octopus
839 pull.twohead
840 repack.useDeltaBaseOffset
841 show.difftree
842 showbranch.default
843 tar.umask
844 transfer.unpackLimit
845 receive.unpackLimit
846 receive.denyNonFastForwards
847 user.name
848 user.email
849 user.signingkey
850 whatchanged.difftree
851 branch. remote.
852 "
853 }
855 _git_remote ()
856 {
857 local i c=1 command
858 while [ $c -lt $COMP_CWORD ]; do
859 i="${COMP_WORDS[c]}"
860 case "$i" in
861 add|show|prune) command="$i"; break ;;
862 esac
863 c=$((++c))
864 done
866 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
867 __gitcomp "add show prune"
868 return
869 fi
871 case "$command" in
872 show|prune)
873 __gitcomp "$(__git_remotes)"
874 ;;
875 *)
876 COMPREPLY=()
877 ;;
878 esac
879 }
881 _git_reset ()
882 {
883 local cur="${COMP_WORDS[COMP_CWORD]}"
884 case "$cur" in
885 --*)
886 __gitcomp "--mixed --hard --soft"
887 return
888 ;;
889 esac
890 __gitcomp "$(__git_refs)"
891 }
893 _git_show ()
894 {
895 local cur="${COMP_WORDS[COMP_CWORD]}"
896 case "$cur" in
897 --pretty=*)
898 __gitcomp "
899 oneline short medium full fuller email raw
900 " "" "${cur##--pretty=}"
901 return
902 ;;
903 --*)
904 __gitcomp "--pretty="
905 return
906 ;;
907 esac
908 __git_complete_file
909 }
911 _git ()
912 {
913 local i c=1 command __git_dir
915 while [ $c -lt $COMP_CWORD ]; do
916 i="${COMP_WORDS[c]}"
917 case "$i" in
918 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
919 --bare) __git_dir="." ;;
920 --version|--help|-p|--paginate) ;;
921 *) command="$i"; break ;;
922 esac
923 c=$((++c))
924 done
926 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
927 case "${COMP_WORDS[COMP_CWORD]}" in
928 --*=*) COMPREPLY=() ;;
929 --*) __gitcomp "--git-dir= --bare --version --exec-path" ;;
930 *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
931 esac
932 return
933 fi
935 local expansion=$(__git_aliased_command "$command")
936 [ "$expansion" ] && command="$expansion"
938 case "$command" in
939 am) _git_am ;;
940 add) _git_add ;;
941 apply) _git_apply ;;
942 bisect) _git_bisect ;;
943 branch) _git_branch ;;
944 checkout) _git_checkout ;;
945 cherry) _git_cherry ;;
946 cherry-pick) _git_cherry_pick ;;
947 commit) _git_commit ;;
948 config) _git_config ;;
949 diff) _git_diff ;;
950 diff-tree) _git_diff_tree ;;
951 fetch) _git_fetch ;;
952 format-patch) _git_format_patch ;;
953 gc) _git_gc ;;
954 log) _git_log ;;
955 ls-remote) _git_ls_remote ;;
956 ls-tree) _git_ls_tree ;;
957 merge) _git_merge;;
958 merge-base) _git_merge_base ;;
959 name-rev) _git_name_rev ;;
960 pull) _git_pull ;;
961 push) _git_push ;;
962 rebase) _git_rebase ;;
963 remote) _git_remote ;;
964 reset) _git_reset ;;
965 show) _git_show ;;
966 show-branch) _git_log ;;
967 whatchanged) _git_log ;;
968 *) COMPREPLY=() ;;
969 esac
970 }
972 _gitk ()
973 {
974 local cur="${COMP_WORDS[COMP_CWORD]}"
975 case "$cur" in
976 --*)
977 __gitcomp "--not --all"
978 return
979 ;;
980 esac
981 __git_complete_revlist
982 }
984 complete -o default -o nospace -F _git git
985 complete -o default -o nospace -F _gitk gitk
986 complete -o default -o nospace -F _git_am git-am
987 complete -o default -o nospace -F _git_apply git-apply
988 complete -o default -o nospace -F _git_bisect git-bisect
989 complete -o default -o nospace -F _git_branch git-branch
990 complete -o default -o nospace -F _git_checkout git-checkout
991 complete -o default -o nospace -F _git_cherry git-cherry
992 complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
993 complete -o default -o nospace -F _git_commit git-commit
994 complete -o default -o nospace -F _git_diff git-diff
995 complete -o default -o nospace -F _git_diff_tree git-diff-tree
996 complete -o default -o nospace -F _git_fetch git-fetch
997 complete -o default -o nospace -F _git_format_patch git-format-patch
998 complete -o default -o nospace -F _git_gc git-gc
999 complete -o default -o nospace -F _git_log git-log
1000 complete -o default -o nospace -F _git_ls_remote git-ls-remote
1001 complete -o default -o nospace -F _git_ls_tree git-ls-tree
1002 complete -o default -o nospace -F _git_merge git-merge
1003 complete -o default -o nospace -F _git_merge_base git-merge-base
1004 complete -o default -o nospace -F _git_name_rev git-name-rev
1005 complete -o default -o nospace -F _git_pull git-pull
1006 complete -o default -o nospace -F _git_push git-push
1007 complete -o default -o nospace -F _git_rebase git-rebase
1008 complete -o default -o nospace -F _git_config git-config
1009 complete -o default -o nospace -F _git_remote git-remote
1010 complete -o default -o nospace -F _git_reset git-reset
1011 complete -o default -o nospace -F _git_show git-show
1012 complete -o default -o nospace -F _git_log git-show-branch
1013 complete -o default -o nospace -F _git_log git-whatchanged
1015 # The following are necessary only for Cygwin, and only are needed
1016 # when the user has tab-completed the executable name and consequently
1017 # included the '.exe' suffix.
1018 #
1019 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1020 complete -o default -o nospace -F _git_add git-add.exe
1021 complete -o default -o nospace -F _git_apply git-apply.exe
1022 complete -o default -o nospace -F _git git.exe
1023 complete -o default -o nospace -F _git_branch git-branch.exe
1024 complete -o default -o nospace -F _git_cherry git-cherry.exe
1025 complete -o default -o nospace -F _git_diff git-diff.exe
1026 complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
1027 complete -o default -o nospace -F _git_format_patch git-format-patch.exe
1028 complete -o default -o nospace -F _git_log git-log.exe
1029 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
1030 complete -o default -o nospace -F _git_merge_base git-merge-base.exe
1031 complete -o default -o nospace -F _git_name_rev git-name-rev.exe
1032 complete -o default -o nospace -F _git_push git-push.exe
1033 complete -o default -o nospace -F _git_config git-config
1034 complete -o default -o nospace -F _git_show git-show.exe
1035 complete -o default -o nospace -F _git_log git-show-branch.exe
1036 complete -o default -o nospace -F _git_log git-whatchanged.exe
1037 fi