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