nicer display of thin pack completion
[git/dscho.git] / contrib / completion / git-completion.bash
blob599b2fc5711bf6022fdb635b08baac16068de7dd
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 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
364 __git_commandlist=
365 __git_commandlist="$(__git_commands 2>/dev/null)"
367 __git_aliases ()
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/=*/}"
376 esac
377 done
380 __git_aliased_command ()
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
389 done
392 __git_whitespacelist="nowarn warn error error-all strip"
394 _git_am ()
396 local cur="${COMP_WORDS[COMP_CWORD]}"
397 if [ -d .dotest ]; then
398 __gitcomp "--skip --resolved"
399 return
401 case "$cur" in
402 --whitespace=*)
403 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
404 return
406 --*)
407 __gitcomp "
408 --signoff --utf8 --binary --3way --interactive
409 --whitespace=
411 return
412 esac
413 COMPREPLY=()
416 _git_apply ()
418 local cur="${COMP_WORDS[COMP_CWORD]}"
419 case "$cur" in
420 --whitespace=*)
421 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
422 return
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
431 return
432 esac
433 COMPREPLY=()
436 _git_add ()
438 local cur="${COMP_WORDS[COMP_CWORD]}"
439 case "$cur" in
440 --*)
441 __gitcomp "--interactive --refresh"
442 return
443 esac
444 COMPREPLY=()
447 _git_bisect ()
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
457 esac
458 c=$((++c))
459 done
461 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
462 __gitcomp "start bad good reset visualize replay log"
463 return
466 case "$command" in
467 bad|good|reset)
468 __gitcomp "$(__git_refs)"
471 COMPREPLY=()
473 esac
476 _git_branch ()
478 __gitcomp "$(__git_refs)"
481 _git_bundle ()
483 local mycword="$COMP_CWORD"
484 case "${COMP_WORDS[0]}" in
485 git)
486 local cmd="${COMP_WORDS[2]}"
487 mycword="$((mycword-1))"
489 git-bundle*)
490 local cmd="${COMP_WORDS[1]}"
492 esac
493 case "$mycword" in
495 __gitcomp "create list-heads verify unbundle"
498 # looking for a file
501 case "$cmd" in
502 create)
503 __git_complete_revlist
505 esac
507 esac
510 _git_checkout ()
512 __gitcomp "$(__git_refs)"
515 _git_cherry ()
517 __gitcomp "$(__git_refs)"
520 _git_cherry_pick ()
522 local cur="${COMP_WORDS[COMP_CWORD]}"
523 case "$cur" in
524 --*)
525 __gitcomp "--edit --no-commit"
528 __gitcomp "$(__git_refs)"
530 esac
533 _git_commit ()
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
542 return
543 esac
544 COMPREPLY=()
547 _git_describe ()
549 __gitcomp "$(__git_refs)"
552 _git_diff ()
554 __git_complete_file
557 _git_diff_tree ()
559 __gitcomp "$(__git_refs)"
562 _git_fetch ()
564 local cur="${COMP_WORDS[COMP_CWORD]}"
566 case "${COMP_WORDS[0]},$COMP_CWORD" in
567 git-fetch*,1)
568 __gitcomp "$(__git_remotes)"
570 git,2)
571 __gitcomp "$(__git_remotes)"
574 case "$cur" in
575 *:*)
576 __gitcomp "$(__git_refs)" "" "${cur#*:}"
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")"
586 esac
588 esac
591 _git_format_patch ()
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
607 return
609 esac
610 __git_complete_revlist
613 _git_gc ()
615 local cur="${COMP_WORDS[COMP_CWORD]}"
616 case "$cur" in
617 --*)
618 __gitcomp "--prune --aggressive"
619 return
621 esac
622 COMPREPLY=()
625 _git_ls_remote ()
627 __gitcomp "$(__git_remotes)"
630 _git_ls_tree ()
632 __git_complete_file
635 _git_log ()
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
645 --date=*)
646 __gitcomp "
647 relative iso8601 rfc2822 short local default
648 " "" "${cur##--date=}"
649 return
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
665 return
667 esac
668 __git_complete_revlist
671 _git_merge ()
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
684 --*)
685 __gitcomp "
686 --no-commit --no-summary --squash --strategy
688 return
689 esac
690 __gitcomp "$(__git_refs)"
693 _git_merge_base ()
695 __gitcomp "$(__git_refs)"
698 _git_name_rev ()
700 __gitcomp "--tags --all --stdin"
703 _git_pull ()
705 local cur="${COMP_WORDS[COMP_CWORD]}"
707 case "${COMP_WORDS[0]},$COMP_CWORD" in
708 git-pull*,1)
709 __gitcomp "$(__git_remotes)"
711 git,2)
712 __gitcomp "$(__git_remotes)"
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")"
722 esac
725 _git_push ()
727 local cur="${COMP_WORDS[COMP_CWORD]}"
729 case "${COMP_WORDS[0]},$COMP_CWORD" in
730 git-push*,1)
731 __gitcomp "$(__git_remotes)"
733 git,2)
734 __gitcomp "$(__git_remotes)"
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#*:}"
747 __gitcomp "$(__git_refs)" + "${cur#+}"
750 __gitcomp "$(__git_refs)"
752 esac
754 esac
757 _git_rebase ()
759 local cur="${COMP_WORDS[COMP_CWORD]}"
760 if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
761 __gitcomp "--continue --skip --abort"
762 return
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
774 --*)
775 __gitcomp "--onto --merge --strategy"
776 return
777 esac
778 __gitcomp "$(__git_refs)"
781 _git_config ()
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
790 branch.*.merge)
791 __gitcomp "$(__git_refs)"
792 return
794 remote.*.fetch)
795 local remote="${prv#remote.}"
796 remote="${remote%.fetch}"
797 __gitcomp "$(__git_refs_remotes "$remote")"
798 return
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
808 pull.twohead|pull.octopus)
809 __gitcomp "$(__git_merge_strategies)"
810 return
812 color.branch|color.diff|color.status)
813 __gitcomp "always never auto"
814 return
816 color.*.*)
817 __gitcomp "
818 black red green yellow blue magenta cyan white
819 bold dim ul blink reverse
821 return
823 *.*)
824 COMPREPLY=()
825 return
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
837 return
839 branch.*.*)
840 local pfx="${cur%.*}."
841 cur="${cur##*.}"
842 __gitcomp "remote merge" "$pfx" "$cur"
843 return
845 branch.*)
846 local pfx="${cur%.*}."
847 cur="${cur#*.}"
848 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
849 return
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
860 remote.*)
861 local pfx="${cur%.*}."
862 cur="${cur#*.}"
863 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
864 return
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.
954 _git_remote ()
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
965 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
966 __gitcomp "add show prune update"
967 return
970 case "$command" in
971 show|prune)
972 __gitcomp "$(__git_remotes)"
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/=*/}"
982 esac
983 done
984 __gitcomp "$c"
987 COMPREPLY=()
989 esac
992 _git_reset ()
994 local cur="${COMP_WORDS[COMP_CWORD]}"
995 case "$cur" in
996 --*)
997 __gitcomp "--mixed --hard --soft"
998 return
1000 esac
1001 __gitcomp "$(__git_refs)"
1004 _git_shortlog ()
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
1018 return
1020 esac
1021 __git_complete_revlist
1024 _git_show ()
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
1034 --*)
1035 __gitcomp "--pretty="
1036 return
1038 esac
1039 __git_complete_file
1042 _git_stash ()
1044 __gitcomp 'list show apply clear'
1047 _git_submodule ()
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
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"
1065 __gitcomp "add status init update"
1067 esac
1068 return
1072 _git_tag ()
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
1085 esac
1086 c=$((++c))
1087 done
1089 case "${COMP_WORDS[COMP_CWORD-1]}" in
1090 -m|-F)
1091 COMPREPLY=()
1093 -*|tag|git-tag)
1094 if [ $f = 1 ]; then
1095 __gitcomp "$(__git_tags)"
1096 else
1097 COMPREPLY=()
1101 __gitcomp "$(__git_refs)"
1103 esac
1106 _git ()
1108 local i c=1 command __git_dir
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
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
1132 *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
1133 esac
1134 return
1137 local expansion=$(__git_aliased_command "$command")
1138 [ "$expansion" ] && command="$expansion"
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
1179 _gitk ()
1181 local cur="${COMP_WORDS[COMP_CWORD]}"
1182 case "$cur" in
1183 --*)
1184 __gitcomp "--not --all"
1185 return
1187 esac
1188 __git_complete_revlist
1191 complete -o default -o nospace -F _git git
1192 complete -o default -o nospace -F _gitk gitk
1193 complete -o default -o nospace -F _git_am git-am
1194 complete -o default -o nospace -F _git_apply git-apply
1195 complete -o default -o nospace -F _git_bisect git-bisect
1196 complete -o default -o nospace -F _git_branch git-branch
1197 complete -o default -o nospace -F _git_bundle git-bundle
1198 complete -o default -o nospace -F _git_checkout git-checkout
1199 complete -o default -o nospace -F _git_cherry git-cherry
1200 complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
1201 complete -o default -o nospace -F _git_commit git-commit
1202 complete -o default -o nospace -F _git_describe git-describe
1203 complete -o default -o nospace -F _git_diff git-diff
1204 complete -o default -o nospace -F _git_fetch git-fetch
1205 complete -o default -o nospace -F _git_format_patch git-format-patch
1206 complete -o default -o nospace -F _git_gc git-gc
1207 complete -o default -o nospace -F _git_log git-log
1208 complete -o default -o nospace -F _git_ls_remote git-ls-remote
1209 complete -o default -o nospace -F _git_ls_tree git-ls-tree
1210 complete -o default -o nospace -F _git_merge git-merge
1211 complete -o default -o nospace -F _git_merge_base git-merge-base
1212 complete -o default -o nospace -F _git_name_rev git-name-rev
1213 complete -o default -o nospace -F _git_pull git-pull
1214 complete -o default -o nospace -F _git_push git-push
1215 complete -o default -o nospace -F _git_rebase git-rebase
1216 complete -o default -o nospace -F _git_config git-config
1217 complete -o default -o nospace -F _git_remote git-remote
1218 complete -o default -o nospace -F _git_reset git-reset
1219 complete -o default -o nospace -F _git_shortlog git-shortlog
1220 complete -o default -o nospace -F _git_show git-show
1221 complete -o default -o nospace -F _git_stash git-stash
1222 complete -o default -o nospace -F _git_submodule git-submodule
1223 complete -o default -o nospace -F _git_log git-show-branch
1224 complete -o default -o nospace -F _git_tag git-tag
1225 complete -o default -o nospace -F _git_log git-whatchanged
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.
1231 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1232 complete -o default -o nospace -F _git_add git-add.exe
1233 complete -o default -o nospace -F _git_apply git-apply.exe
1234 complete -o default -o nospace -F _git git.exe
1235 complete -o default -o nospace -F _git_branch git-branch.exe
1236 complete -o default -o nospace -F _git_bundle git-bundle.exe
1237 complete -o default -o nospace -F _git_cherry git-cherry.exe
1238 complete -o default -o nospace -F _git_describe git-describe.exe
1239 complete -o default -o nospace -F _git_diff git-diff.exe
1240 complete -o default -o nospace -F _git_format_patch git-format-patch.exe
1241 complete -o default -o nospace -F _git_log git-log.exe
1242 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
1243 complete -o default -o nospace -F _git_merge_base git-merge-base.exe
1244 complete -o default -o nospace -F _git_name_rev git-name-rev.exe
1245 complete -o default -o nospace -F _git_push git-push.exe
1246 complete -o default -o nospace -F _git_config git-config
1247 complete -o default -o nospace -F _git_shortlog git-shortlog.exe
1248 complete -o default -o nospace -F _git_show git-show.exe
1249 complete -o default -o nospace -F _git_log git-show-branch.exe
1250 complete -o default -o nospace -F _git_tag git-tag.exe
1251 complete -o default -o nospace -F _git_log git-whatchanged.exe