Add shortcuts for very often used options.
[git/dscho.git] / contrib / completion / git-completion.bash
blobe76093074035d4b9aa4d41e993b5c29e359dad53
2 # bash completion support for core Git.
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.
8 # The contained completion routines provide support for completing:
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
17 # To use these routines:
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
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.
29 # 4) Consider changing your PS1 to also show the current branch:
30 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
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.
36 # To submit patches:
38 # *) Read Documentation/SubmittingPatches
39 # *) Send all patches to the current maintainer:
41 # "Shawn O. Pearce" <spearce@spearce.org>
43 # *) Always CC the Git mailing list:
45 # git@vger.kernel.org
48 __gitdir ()
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
58 elif [ -d "$1/.git" ]; then
59 echo "$1/.git"
60 else
61 echo "$1"
65 __git_ps1 ()
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/}"
77 __gitcomp ()
79 local all c s=$'\n' IFS=' '$'\t'$'\n'
80 local cur="${COMP_WORDS[COMP_CWORD]}"
81 if [ $# -gt 2 ]; then
82 cur="$3"
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
96 __git_heads ()
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
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
117 __git_tags ()
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
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
138 __git_refs ()
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
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
167 __git_refs2 ()
169 local i
170 for i in $(__git_refs "$1"); do
171 echo "$i:$i"
172 done
175 __git_refs_remotes ()
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/}"
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
192 __git_remotes ()
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=*/}"
207 esac
208 done
211 __git_merge_strategies ()
213 if [ -n "$__git_merge_strategylist" ]; then
214 echo "$__git_merge_strategylist"
215 return
217 sed -n "/^all_strategies='/{
218 s/^all_strategies='//
219 s/'//
222 }" "$(git --exec-path)/git-merge"
224 __git_merge_strategylist=
225 __git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
227 __git_complete_file ()
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/"
242 ls="$ref"
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,$,/,
252 s/^.* //')" \
253 -- "$cur"))
256 __gitcomp "$(__git_refs)"
258 esac
261 __git_complete_revlist ()
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"
270 *..*)
271 pfx="${cur%..*}.."
272 cur="${cur#*..}"
273 __gitcomp "$(__git_refs)" "$pfx" "$cur"
276 __gitcomp "$cur."
279 __gitcomp "$(__git_refs)"
281 esac
284 __git_commands ()
286 if [ -n "$__git_commandlist" ]; then
287 echo "$__git_commandlist"
288 return
290 local i IFS=" "$'\n'
291 for i in $(git help -a|egrep '^ ')
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 svnimport) : import;;
350 symbolic-ref) : plumbing;;
351 tar-tree) : deprecated;;
352 unpack-file) : plumbing;;
353 unpack-objects) : plumbing;;
354 update-index) : plumbing;;
355 update-ref) : plumbing;;
356 update-server-info) : daemon;;
357 upload-archive) : plumbing;;
358 upload-pack) : plumbing;;
359 write-tree) : plumbing;;
360 verify-tag) : plumbing;;
361 *) echo $i;;
362 esac
363 done
365 __git_commandlist=
366 __git_commandlist="$(__git_commands 2>/dev/null)"
368 __git_aliases ()
370 local i IFS=$'\n'
371 for i in $(git --git-dir="$(__gitdir)" config --list); do
372 case "$i" in
373 alias.*)
374 i="${i#alias.}"
375 echo "${i/=*/}"
377 esac
378 done
381 __git_aliased_command ()
383 local word cmdline=$(git --git-dir="$(__gitdir)" \
384 config --get "alias.$1")
385 for word in $cmdline; do
386 if [ "${word##-*}" ]; then
387 echo $word
388 return
390 done
393 __git_whitespacelist="nowarn warn error error-all strip"
395 _git_am ()
397 local cur="${COMP_WORDS[COMP_CWORD]}"
398 if [ -d .dotest ]; then
399 __gitcomp "--skip --resolved"
400 return
402 case "$cur" in
403 --whitespace=*)
404 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
405 return
407 --*)
408 __gitcomp "
409 --signoff --utf8 --binary --3way --interactive
410 --whitespace=
412 return
413 esac
414 COMPREPLY=()
417 _git_apply ()
419 local cur="${COMP_WORDS[COMP_CWORD]}"
420 case "$cur" in
421 --whitespace=*)
422 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
423 return
425 --*)
426 __gitcomp "
427 --stat --numstat --summary --check --index
428 --cached --index-info --reverse --reject --unidiff-zero
429 --apply --no-add --exclude=
430 --whitespace= --inaccurate-eof --verbose
432 return
433 esac
434 COMPREPLY=()
437 _git_add ()
439 local cur="${COMP_WORDS[COMP_CWORD]}"
440 case "$cur" in
441 --*)
442 __gitcomp "--interactive --refresh"
443 return
444 esac
445 COMPREPLY=()
448 _git_bisect ()
450 local i c=1 command
451 while [ $c -lt $COMP_CWORD ]; do
452 i="${COMP_WORDS[c]}"
453 case "$i" in
454 start|bad|good|reset|visualize|replay|log)
455 command="$i"
456 break
458 esac
459 c=$((++c))
460 done
462 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
463 __gitcomp "start bad good reset visualize replay log"
464 return
467 case "$command" in
468 bad|good|reset)
469 __gitcomp "$(__git_refs)"
472 COMPREPLY=()
474 esac
477 _git_branch ()
479 __gitcomp "$(__git_refs)"
482 _git_bundle ()
484 local mycword="$COMP_CWORD"
485 case "${COMP_WORDS[0]}" in
486 git)
487 local cmd="${COMP_WORDS[2]}"
488 mycword="$((mycword-1))"
490 git-bundle*)
491 local cmd="${COMP_WORDS[1]}"
493 esac
494 case "$mycword" in
496 __gitcomp "create list-heads verify unbundle"
499 # looking for a file
502 case "$cmd" in
503 create)
504 __git_complete_revlist
506 esac
508 esac
511 _git_checkout ()
513 __gitcomp "$(__git_refs)"
516 _git_cherry ()
518 __gitcomp "$(__git_refs)"
521 _git_cherry_pick ()
523 local cur="${COMP_WORDS[COMP_CWORD]}"
524 case "$cur" in
525 --*)
526 __gitcomp "--edit --no-commit"
529 __gitcomp "$(__git_refs)"
531 esac
534 _git_commit ()
536 local cur="${COMP_WORDS[COMP_CWORD]}"
537 case "$cur" in
538 --*)
539 __gitcomp "
540 --all --author= --signoff --verify --no-verify
541 --edit --amend --include --only
543 return
544 esac
545 COMPREPLY=()
548 _git_describe ()
550 __gitcomp "$(__git_refs)"
553 _git_diff ()
555 __git_complete_file
558 _git_diff_tree ()
560 __gitcomp "$(__git_refs)"
563 _git_fetch ()
565 local cur="${COMP_WORDS[COMP_CWORD]}"
567 case "${COMP_WORDS[0]},$COMP_CWORD" in
568 git-fetch*,1)
569 __gitcomp "$(__git_remotes)"
571 git,2)
572 __gitcomp "$(__git_remotes)"
575 case "$cur" in
576 *:*)
577 __gitcomp "$(__git_refs)" "" "${cur#*:}"
580 local remote
581 case "${COMP_WORDS[0]}" in
582 git-fetch) remote="${COMP_WORDS[1]}" ;;
583 git) remote="${COMP_WORDS[2]}" ;;
584 esac
585 __gitcomp "$(__git_refs2 "$remote")"
587 esac
589 esac
592 _git_format_patch ()
594 local cur="${COMP_WORDS[COMP_CWORD]}"
595 case "$cur" in
596 --*)
597 __gitcomp "
598 --stdout --attach --thread
599 --output-directory
600 --numbered --start-number
601 --numbered-files
602 --keep-subject
603 --signoff
604 --in-reply-to=
605 --full-index --binary
606 --not --all
608 return
610 esac
611 __git_complete_revlist
614 _git_gc ()
616 local cur="${COMP_WORDS[COMP_CWORD]}"
617 case "$cur" in
618 --*)
619 __gitcomp "--prune --aggressive"
620 return
622 esac
623 COMPREPLY=()
626 _git_ls_remote ()
628 __gitcomp "$(__git_remotes)"
631 _git_ls_tree ()
633 __git_complete_file
636 _git_log ()
638 local cur="${COMP_WORDS[COMP_CWORD]}"
639 case "$cur" in
640 --pretty=*)
641 __gitcomp "
642 oneline short medium full fuller email raw
643 " "" "${cur##--pretty=}"
644 return
646 --date=*)
647 __gitcomp "
648 relative iso8601 rfc2822 short local default
649 " "" "${cur##--date=}"
650 return
652 --*)
653 __gitcomp "
654 --max-count= --max-age= --since= --after=
655 --min-age= --before= --until=
656 --root --topo-order --date-order --reverse
657 --no-merges --follow
658 --abbrev-commit --abbrev=
659 --relative-date --date=
660 --author= --committer= --grep=
661 --all-match
662 --pretty= --name-status --name-only --raw
663 --not --all
664 --left-right --cherry-pick
666 return
668 esac
669 __git_complete_revlist
672 _git_merge ()
674 local cur="${COMP_WORDS[COMP_CWORD]}"
675 case "${COMP_WORDS[COMP_CWORD-1]}" in
676 -s|--strategy)
677 __gitcomp "$(__git_merge_strategies)"
678 return
679 esac
680 case "$cur" in
681 --strategy=*)
682 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
683 return
685 --*)
686 __gitcomp "
687 --no-commit --no-summary --squash --strategy
689 return
690 esac
691 __gitcomp "$(__git_refs)"
694 _git_merge_base ()
696 __gitcomp "$(__git_refs)"
699 _git_name_rev ()
701 __gitcomp "--tags --all --stdin"
704 _git_pull ()
706 local cur="${COMP_WORDS[COMP_CWORD]}"
708 case "${COMP_WORDS[0]},$COMP_CWORD" in
709 git-pull*,1)
710 __gitcomp "$(__git_remotes)"
712 git,2)
713 __gitcomp "$(__git_remotes)"
716 local remote
717 case "${COMP_WORDS[0]}" in
718 git-pull) remote="${COMP_WORDS[1]}" ;;
719 git) remote="${COMP_WORDS[2]}" ;;
720 esac
721 __gitcomp "$(__git_refs "$remote")"
723 esac
726 _git_push ()
728 local cur="${COMP_WORDS[COMP_CWORD]}"
730 case "${COMP_WORDS[0]},$COMP_CWORD" in
731 git-push*,1)
732 __gitcomp "$(__git_remotes)"
734 git,2)
735 __gitcomp "$(__git_remotes)"
738 case "$cur" in
739 *:*)
740 local remote
741 case "${COMP_WORDS[0]}" in
742 git-push) remote="${COMP_WORDS[1]}" ;;
743 git) remote="${COMP_WORDS[2]}" ;;
744 esac
745 __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
748 __gitcomp "$(__git_refs)" + "${cur#+}"
751 __gitcomp "$(__git_refs)"
753 esac
755 esac
758 _git_rebase ()
760 local cur="${COMP_WORDS[COMP_CWORD]}"
761 if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
762 __gitcomp "--continue --skip --abort"
763 return
765 case "${COMP_WORDS[COMP_CWORD-1]}" in
766 -s|--strategy)
767 __gitcomp "$(__git_merge_strategies)"
768 return
769 esac
770 case "$cur" in
771 --strategy=*)
772 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
773 return
775 --*)
776 __gitcomp "--onto --merge --strategy"
777 return
778 esac
779 __gitcomp "$(__git_refs)"
782 _git_config ()
784 local cur="${COMP_WORDS[COMP_CWORD]}"
785 local prv="${COMP_WORDS[COMP_CWORD-1]}"
786 case "$prv" in
787 branch.*.remote)
788 __gitcomp "$(__git_remotes)"
789 return
791 branch.*.merge)
792 __gitcomp "$(__git_refs)"
793 return
795 remote.*.fetch)
796 local remote="${prv#remote.}"
797 remote="${remote%.fetch}"
798 __gitcomp "$(__git_refs_remotes "$remote")"
799 return
801 remote.*.push)
802 local remote="${prv#remote.}"
803 remote="${remote%.push}"
804 __gitcomp "$(git --git-dir="$(__gitdir)" \
805 for-each-ref --format='%(refname):%(refname)' \
806 refs/heads)"
807 return
809 pull.twohead|pull.octopus)
810 __gitcomp "$(__git_merge_strategies)"
811 return
813 color.branch|color.diff|color.status)
814 __gitcomp "always never auto"
815 return
817 color.*.*)
818 __gitcomp "
819 black red green yellow blue magenta cyan white
820 bold dim ul blink reverse
822 return
824 *.*)
825 COMPREPLY=()
826 return
828 esac
829 case "$cur" in
830 --*)
831 __gitcomp "
832 --global --system --file=
833 --list --replace-all
834 --get --get-all --get-regexp
835 --add --unset --unset-all
836 --remove-section --rename-section
838 return
840 branch.*.*)
841 local pfx="${cur%.*}."
842 cur="${cur##*.}"
843 __gitcomp "remote merge" "$pfx" "$cur"
844 return
846 branch.*)
847 local pfx="${cur%.*}."
848 cur="${cur#*.}"
849 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
850 return
852 remote.*.*)
853 local pfx="${cur%.*}."
854 cur="${cur##*.}"
855 __gitcomp "
856 url fetch push skipDefaultUpdate
857 receivepack uploadpack tagopt
858 " "$pfx" "$cur"
859 return
861 remote.*)
862 local pfx="${cur%.*}."
863 cur="${cur#*.}"
864 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
865 return
867 esac
868 __gitcomp "
869 apply.whitespace
870 core.fileMode
871 core.gitProxy
872 core.ignoreStat
873 core.preferSymlinkRefs
874 core.logAllRefUpdates
875 core.loosecompression
876 core.repositoryFormatVersion
877 core.sharedRepository
878 core.warnAmbiguousRefs
879 core.compression
880 core.legacyHeaders
881 core.packedGitWindowSize
882 core.packedGitLimit
883 clean.requireForce
884 color.branch
885 color.branch.current
886 color.branch.local
887 color.branch.remote
888 color.branch.plain
889 color.diff
890 color.diff.plain
891 color.diff.meta
892 color.diff.frag
893 color.diff.old
894 color.diff.new
895 color.diff.commit
896 color.diff.whitespace
897 color.pager
898 color.status
899 color.status.header
900 color.status.added
901 color.status.changed
902 color.status.untracked
903 diff.renameLimit
904 diff.renames
905 fetch.unpackLimit
906 format.headers
907 format.subjectprefix
908 gitcvs.enabled
909 gitcvs.logfile
910 gitcvs.allbinary
911 gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dvpass
912 gc.packrefs
913 gc.reflogexpire
914 gc.reflogexpireunreachable
915 gc.rerereresolved
916 gc.rerereunresolved
917 http.sslVerify
918 http.sslCert
919 http.sslKey
920 http.sslCAInfo
921 http.sslCAPath
922 http.maxRequests
923 http.lowSpeedLimit
924 http.lowSpeedTime
925 http.noEPSV
926 i18n.commitEncoding
927 i18n.logOutputEncoding
928 log.showroot
929 merge.tool
930 merge.summary
931 merge.verbosity
932 pack.window
933 pack.depth
934 pack.windowMemory
935 pack.compression
936 pack.deltaCacheSize
937 pack.deltaCacheLimit
938 pull.octopus
939 pull.twohead
940 repack.useDeltaBaseOffset
941 show.difftree
942 showbranch.default
943 tar.umask
944 transfer.unpackLimit
945 receive.unpackLimit
946 receive.denyNonFastForwards
947 user.name
948 user.email
949 user.signingkey
950 whatchanged.difftree
951 branch. remote.
955 _git_remote ()
957 local i c=1 command
958 while [ $c -lt $COMP_CWORD ]; do
959 i="${COMP_WORDS[c]}"
960 case "$i" in
961 add|show|prune|update) command="$i"; break ;;
962 esac
963 c=$((++c))
964 done
966 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
967 __gitcomp "add show prune update"
968 return
971 case "$command" in
972 show|prune)
973 __gitcomp "$(__git_remotes)"
975 update)
976 local i c='' IFS=$'\n'
977 for i in $(git --git-dir="$(__gitdir)" config --list); do
978 case "$i" in
979 remotes.*)
980 i="${i#remotes.}"
981 c="$c ${i/=*/}"
983 esac
984 done
985 __gitcomp "$c"
988 COMPREPLY=()
990 esac
993 _git_reset ()
995 local cur="${COMP_WORDS[COMP_CWORD]}"
996 case "$cur" in
997 --*)
998 __gitcomp "--mixed --hard --soft"
999 return
1001 esac
1002 __gitcomp "$(__git_refs)"
1005 _git_shortlog ()
1007 local cur="${COMP_WORDS[COMP_CWORD]}"
1008 case "$cur" in
1009 --*)
1010 __gitcomp "
1011 --max-count= --max-age= --since= --after=
1012 --min-age= --before= --until=
1013 --no-merges
1014 --author= --committer= --grep=
1015 --all-match
1016 --not --all
1017 --numbered --summary
1019 return
1021 esac
1022 __git_complete_revlist
1025 _git_show ()
1027 local cur="${COMP_WORDS[COMP_CWORD]}"
1028 case "$cur" in
1029 --pretty=*)
1030 __gitcomp "
1031 oneline short medium full fuller email raw
1032 " "" "${cur##--pretty=}"
1033 return
1035 --*)
1036 __gitcomp "--pretty="
1037 return
1039 esac
1040 __git_complete_file
1043 _git_stash ()
1045 __gitcomp 'list show apply clear'
1048 _git_submodule ()
1050 local i c=1 command
1051 while [ $c -lt $COMP_CWORD ]; do
1052 i="${COMP_WORDS[c]}"
1053 case "$i" in
1054 add|status|init|update) command="$i"; break ;;
1055 esac
1056 c=$((++c))
1057 done
1059 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
1060 local cur="${COMP_WORDS[COMP_CWORD]}"
1061 case "$cur" in
1062 --*)
1063 __gitcomp "--quiet --cached"
1066 __gitcomp "add status init update"
1068 esac
1069 return
1073 _git_tag ()
1075 local i c=1 f=0
1076 while [ $c -lt $COMP_CWORD ]; do
1077 i="${COMP_WORDS[c]}"
1078 case "$i" in
1079 -d|-v)
1080 __gitcomp "$(__git_tags)"
1081 return
1086 esac
1087 c=$((++c))
1088 done
1090 case "${COMP_WORDS[COMP_CWORD-1]}" in
1091 -m|-F)
1092 COMPREPLY=()
1094 -*|tag|git-tag)
1095 if [ $f = 1 ]; then
1096 __gitcomp "$(__git_tags)"
1097 else
1098 COMPREPLY=()
1102 __gitcomp "$(__git_refs)"
1104 esac
1107 _git ()
1109 local i c=1 command __git_dir
1111 while [ $c -lt $COMP_CWORD ]; do
1112 i="${COMP_WORDS[c]}"
1113 case "$i" in
1114 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1115 --bare) __git_dir="." ;;
1116 --version|--help|-p|--paginate) ;;
1117 *) command="$i"; break ;;
1118 esac
1119 c=$((++c))
1120 done
1122 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
1123 case "${COMP_WORDS[COMP_CWORD]}" in
1124 --*=*) COMPREPLY=() ;;
1125 --*) __gitcomp "
1126 --no-pager
1127 --git-dir=
1128 --bare
1129 --version
1130 --exec-path
1133 *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
1134 esac
1135 return
1138 local expansion=$(__git_aliased_command "$command")
1139 [ "$expansion" ] && command="$expansion"
1141 case "$command" in
1142 am) _git_am ;;
1143 add) _git_add ;;
1144 apply) _git_apply ;;
1145 bisect) _git_bisect ;;
1146 bundle) _git_bundle ;;
1147 branch) _git_branch ;;
1148 checkout) _git_checkout ;;
1149 cherry) _git_cherry ;;
1150 cherry-pick) _git_cherry_pick ;;
1151 commit) _git_commit ;;
1152 config) _git_config ;;
1153 describe) _git_describe ;;
1154 diff) _git_diff ;;
1155 fetch) _git_fetch ;;
1156 format-patch) _git_format_patch ;;
1157 gc) _git_gc ;;
1158 log) _git_log ;;
1159 ls-remote) _git_ls_remote ;;
1160 ls-tree) _git_ls_tree ;;
1161 merge) _git_merge;;
1162 merge-base) _git_merge_base ;;
1163 name-rev) _git_name_rev ;;
1164 pull) _git_pull ;;
1165 push) _git_push ;;
1166 rebase) _git_rebase ;;
1167 remote) _git_remote ;;
1168 reset) _git_reset ;;
1169 shortlog) _git_shortlog ;;
1170 show) _git_show ;;
1171 show-branch) _git_log ;;
1172 stash) _git_stash ;;
1173 submodule) _git_submodule ;;
1174 tag) _git_tag ;;
1175 whatchanged) _git_log ;;
1176 *) COMPREPLY=() ;;
1177 esac
1180 _gitk ()
1182 local cur="${COMP_WORDS[COMP_CWORD]}"
1183 case "$cur" in
1184 --*)
1185 __gitcomp "--not --all"
1186 return
1188 esac
1189 __git_complete_revlist
1192 complete -o default -o nospace -F _git git
1193 complete -o default -o nospace -F _gitk gitk
1194 complete -o default -o nospace -F _git_am git-am
1195 complete -o default -o nospace -F _git_apply git-apply
1196 complete -o default -o nospace -F _git_bisect git-bisect
1197 complete -o default -o nospace -F _git_branch git-branch
1198 complete -o default -o nospace -F _git_bundle git-bundle
1199 complete -o default -o nospace -F _git_checkout git-checkout
1200 complete -o default -o nospace -F _git_cherry git-cherry
1201 complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
1202 complete -o default -o nospace -F _git_commit git-commit
1203 complete -o default -o nospace -F _git_describe git-describe
1204 complete -o default -o nospace -F _git_diff git-diff
1205 complete -o default -o nospace -F _git_fetch git-fetch
1206 complete -o default -o nospace -F _git_format_patch git-format-patch
1207 complete -o default -o nospace -F _git_gc git-gc
1208 complete -o default -o nospace -F _git_log git-log
1209 complete -o default -o nospace -F _git_ls_remote git-ls-remote
1210 complete -o default -o nospace -F _git_ls_tree git-ls-tree
1211 complete -o default -o nospace -F _git_merge git-merge
1212 complete -o default -o nospace -F _git_merge_base git-merge-base
1213 complete -o default -o nospace -F _git_name_rev git-name-rev
1214 complete -o default -o nospace -F _git_pull git-pull
1215 complete -o default -o nospace -F _git_push git-push
1216 complete -o default -o nospace -F _git_rebase git-rebase
1217 complete -o default -o nospace -F _git_config git-config
1218 complete -o default -o nospace -F _git_remote git-remote
1219 complete -o default -o nospace -F _git_reset git-reset
1220 complete -o default -o nospace -F _git_shortlog git-shortlog
1221 complete -o default -o nospace -F _git_show git-show
1222 complete -o default -o nospace -F _git_stash git-stash
1223 complete -o default -o nospace -F _git_submodule git-submodule
1224 complete -o default -o nospace -F _git_log git-show-branch
1225 complete -o default -o nospace -F _git_tag git-tag
1226 complete -o default -o nospace -F _git_log git-whatchanged
1228 # The following are necessary only for Cygwin, and only are needed
1229 # when the user has tab-completed the executable name and consequently
1230 # included the '.exe' suffix.
1232 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1233 complete -o default -o nospace -F _git_add git-add.exe
1234 complete -o default -o nospace -F _git_apply git-apply.exe
1235 complete -o default -o nospace -F _git git.exe
1236 complete -o default -o nospace -F _git_branch git-branch.exe
1237 complete -o default -o nospace -F _git_bundle git-bundle.exe
1238 complete -o default -o nospace -F _git_cherry git-cherry.exe
1239 complete -o default -o nospace -F _git_describe git-describe.exe
1240 complete -o default -o nospace -F _git_diff git-diff.exe
1241 complete -o default -o nospace -F _git_format_patch git-format-patch.exe
1242 complete -o default -o nospace -F _git_log git-log.exe
1243 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
1244 complete -o default -o nospace -F _git_merge_base git-merge-base.exe
1245 complete -o default -o nospace -F _git_name_rev git-name-rev.exe
1246 complete -o default -o nospace -F _git_push git-push.exe
1247 complete -o default -o nospace -F _git_config git-config
1248 complete -o default -o nospace -F _git_shortlog git-shortlog.exe
1249 complete -o default -o nospace -F _git_show git-show.exe
1250 complete -o default -o nospace -F _git_log git-show-branch.exe
1251 complete -o default -o nospace -F _git_tag git-tag.exe
1252 complete -o default -o nospace -F _git_log git-whatchanged.exe