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