Code

bash: Offer --prune completion for git-gc.
[git.git] / contrib / completion / git-completion.bash
1 #
2 # bash completion support for core Git.
3 #
4 # Copyright (C) 2006,2007 Shawn Pearce
5 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
6 #
7 # The contained completion routines provide support for completing:
8 #
9 #    *) local and remote branch names
10 #    *) local and remote tag names
11 #    *) .git/remotes file names
12 #    *) git 'subcommands'
13 #    *) tree paths within 'ref:path/to/file' expressions
14 #
15 # To use these routines:
16 #
17 #    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
18 #    2) Added the following line to your .bashrc:
19 #        source ~/.git-completion.sh
20 #
21 #    3) You may want to make sure the git executable is available
22 #       in your PATH before this script is sourced, as some caching
23 #       is performed while the script loads.  If git isn't found
24 #       at source time then all lookups will be done on demand,
25 #       which may be slightly slower.
26 #
27 #    4) Consider changing your PS1 to also show the current branch:
28 #        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
29 #
30 #       The argument to __git_ps1 will be displayed only if you
31 #       are currently in a git repository.  The %s token will be
32 #       the name of the current branch.
33 #
35 __gitdir ()
36 {
37         if [ -z "$1" ]; then
38                 if [ -n "$__git_dir" ]; then
39                         echo "$__git_dir"
40                 elif [ -d .git ]; then
41                         echo .git
42                 else
43                         git rev-parse --git-dir 2>/dev/null
44                 fi
45         elif [ -d "$1/.git" ]; then
46                 echo "$1/.git"
47         else
48                 echo "$1"
49         fi
50 }
52 __git_ps1 ()
53 {
54         local b="$(git symbolic-ref HEAD 2>/dev/null)"
55         if [ -n "$b" ]; then
56                 if [ -n "$1" ]; then
57                         printf "$1" "${b##refs/heads/}"
58                 else
59                         printf " (%s)" "${b##refs/heads/}"
60                 fi
61         fi
62 }
64 __gitcomp ()
65 {
66         local all c s=$'\n' IFS=' '$'\t'$'\n'
67         local cur="${COMP_WORDS[COMP_CWORD]}"
68         if [ $# -gt 2 ]; then
69                 cur="$3"
70         fi
71         for c in $1; do
72                 case "$c$4" in
73                 --*=*) all="$all$c$4$s" ;;
74                 *.)    all="$all$c$4$s" ;;
75                 *)     all="$all$c$4 $s" ;;
76                 esac
77         done
78         IFS=$s
79         COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
80         return
81 }
83 __git_heads ()
84 {
85         local cmd i is_hash=y dir="$(__gitdir "$1")"
86         if [ -d "$dir" ]; then
87                 for i in $(git --git-dir="$dir" \
88                         for-each-ref --format='%(refname)' \
89                         refs/heads ); do
90                         echo "${i#refs/heads/}"
91                 done
92                 return
93         fi
94         for i in $(git-ls-remote "$1" 2>/dev/null); do
95                 case "$is_hash,$i" in
96                 y,*) is_hash=n ;;
97                 n,*^{}) is_hash=y ;;
98                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
99                 n,*) is_hash=y; echo "$i" ;;
100                 esac
101         done
104 __git_refs ()
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
133 __git_refs2 ()
135         local i
136         for i in $(__git_refs "$1"); do
137                 echo "$i:$i"
138         done
141 __git_refs_remotes ()
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
158 __git_remotes ()
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
177 __git_merge_strategies ()
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"
190 __git_merge_strategylist=
191 __git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
193 __git_complete_file ()
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
227 __git_complete_revlist ()
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
250 __git_commands ()
252         if [ -n "$__git_commandlist" ]; then
253                 echo "$__git_commandlist"
254                 return
255         fi
256         local i IFS=" "$'\n'
257         for i in $(git help -a|egrep '^ ')
258         do
259                 case $i in
260                 add--interactive) : plumbing;;
261                 applymbox)        : ask gittus;;
262                 applypatch)       : ask gittus;;
263                 archimport)       : import;;
264                 cat-file)         : plumbing;;
265                 check-ref-format) : plumbing;;
266                 commit-tree)      : plumbing;;
267                 convert-objects)  : plumbing;;
268                 cvsexportcommit)  : export;;
269                 cvsimport)        : import;;
270                 cvsserver)        : daemon;;
271                 daemon)           : daemon;;
272                 diff-stages)      : nobody uses it;;
273                 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
326 __git_commandlist=
327 __git_commandlist="$(__git_commands 2>/dev/null)"
329 __git_aliases ()
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
342 __git_aliased_command ()
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
354 __git_whitespacelist="nowarn warn error error-all strip"
356 _git_am ()
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=()
378 _git_apply ()
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=()
398 _git_add ()
400         local cur="${COMP_WORDS[COMP_CWORD]}"
401         case "$cur" in
402         --*)
403                 __gitcomp "--interactive"
404                 return
405         esac
406         COMPREPLY=()
409 _git_branch ()
411         __gitcomp "$(__git_refs)"
414 _git_checkout ()
416         __gitcomp "$(__git_refs)"
419 _git_cherry ()
421         __gitcomp "$(__git_refs)"
424 _git_cherry_pick ()
426         local cur="${COMP_WORDS[COMP_CWORD]}"
427         case "$cur" in
428         --*)
429                 __gitcomp "--edit --no-commit"
430                 ;;
431         *)
432                 __gitcomp "$(__git_refs)"
433                 ;;
434         esac
437 _git_commit ()
439         local cur="${COMP_WORDS[COMP_CWORD]}"
440         case "$cur" in
441         --*)
442                 __gitcomp "
443                         --all --author= --signoff --verify --no-verify
444                         --edit --amend --include --only
445                         "
446                 return
447         esac
448         COMPREPLY=()
451 _git_diff ()
453         __git_complete_file
456 _git_diff_tree ()
458         __gitcomp "$(__git_refs)"
461 _git_fetch ()
463         local cur="${COMP_WORDS[COMP_CWORD]}"
465         case "${COMP_WORDS[0]},$COMP_CWORD" in
466         git-fetch*,1)
467                 __gitcomp "$(__git_remotes)"
468                 ;;
469         git,2)
470                 __gitcomp "$(__git_remotes)"
471                 ;;
472         *)
473                 case "$cur" in
474                 *:*)
475                         __gitcomp "$(__git_refs)" "" "${cur#*:}"
476                         ;;
477                 *)
478                         local remote
479                         case "${COMP_WORDS[0]}" in
480                         git-fetch) remote="${COMP_WORDS[1]}" ;;
481                         git)       remote="${COMP_WORDS[2]}" ;;
482                         esac
483                         __gitcomp "$(__git_refs2 "$remote")"
484                         ;;
485                 esac
486                 ;;
487         esac
490 _git_format_patch ()
492         local cur="${COMP_WORDS[COMP_CWORD]}"
493         case "$cur" in
494         --*)
495                 __gitcomp "
496                         --stdout --attach --thread
497                         --output-directory
498                         --numbered --start-number
499                         --keep-subject
500                         --signoff
501                         --in-reply-to=
502                         --full-index --binary
503                         --not --all
504                         "
505                 return
506                 ;;
507         esac
508         __git_complete_revlist
511 _git_gc ()
513         local cur="${COMP_WORDS[COMP_CWORD]}"
514         case "$cur" in
515         --*)
516                 __gitcomp "--prune"
517                 return
518                 ;;
519         esac
520         COMPREPLY=()
523 _git_ls_remote ()
525         __gitcomp "$(__git_remotes)"
528 _git_ls_tree ()
530         __git_complete_file
533 _git_log ()
535         local cur="${COMP_WORDS[COMP_CWORD]}"
536         case "$cur" in
537         --pretty=*)
538                 __gitcomp "
539                         oneline short medium full fuller email raw
540                         " "" "${cur##--pretty=}"
541                 return
542                 ;;
543         --*)
544                 __gitcomp "
545                         --max-count= --max-age= --since= --after=
546                         --min-age= --before= --until=
547                         --root --not --topo-order --date-order
548                         --no-merges
549                         --abbrev-commit --abbrev=
550                         --relative-date
551                         --author= --committer= --grep=
552                         --all-match
553                         --pretty= --name-status --name-only
554                         --not --all
555                         "
556                 return
557                 ;;
558         esac
559         __git_complete_revlist
562 _git_merge ()
564         local cur="${COMP_WORDS[COMP_CWORD]}"
565         case "${COMP_WORDS[COMP_CWORD-1]}" in
566         -s|--strategy)
567                 __gitcomp "$(__git_merge_strategies)"
568                 return
569         esac
570         case "$cur" in
571         --strategy=*)
572                 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
573                 return
574                 ;;
575         --*)
576                 __gitcomp "
577                         --no-commit --no-summary --squash --strategy
578                         "
579                 return
580         esac
581         __gitcomp "$(__git_refs)"
584 _git_merge_base ()
586         __gitcomp "$(__git_refs)"
589 _git_name_rev ()
591         __gitcomp "--tags --all --stdin"
594 _git_pull ()
596         local cur="${COMP_WORDS[COMP_CWORD]}"
598         case "${COMP_WORDS[0]},$COMP_CWORD" in
599         git-pull*,1)
600                 __gitcomp "$(__git_remotes)"
601                 ;;
602         git,2)
603                 __gitcomp "$(__git_remotes)"
604                 ;;
605         *)
606                 local remote
607                 case "${COMP_WORDS[0]}" in
608                 git-pull)  remote="${COMP_WORDS[1]}" ;;
609                 git)       remote="${COMP_WORDS[2]}" ;;
610                 esac
611                 __gitcomp "$(__git_refs "$remote")"
612                 ;;
613         esac
616 _git_push ()
618         local cur="${COMP_WORDS[COMP_CWORD]}"
620         case "${COMP_WORDS[0]},$COMP_CWORD" in
621         git-push*,1)
622                 __gitcomp "$(__git_remotes)"
623                 ;;
624         git,2)
625                 __gitcomp "$(__git_remotes)"
626                 ;;
627         *)
628                 case "$cur" in
629                 *:*)
630                         local remote
631                         case "${COMP_WORDS[0]}" in
632                         git-push)  remote="${COMP_WORDS[1]}" ;;
633                         git)       remote="${COMP_WORDS[2]}" ;;
634                         esac
635                         __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
636                         ;;
637                 *)
638                         __gitcomp "$(__git_refs2)"
639                         ;;
640                 esac
641                 ;;
642         esac
645 _git_rebase ()
647         local cur="${COMP_WORDS[COMP_CWORD]}"
648         if [ -d .dotest ]; then
649                 __gitcomp "--continue --skip --abort"
650                 return
651         fi
652         case "${COMP_WORDS[COMP_CWORD-1]}" in
653         -s|--strategy)
654                 __gitcomp "$(__git_merge_strategies)"
655                 return
656         esac
657         case "$cur" in
658         --strategy=*)
659                 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
660                 return
661                 ;;
662         --*)
663                 __gitcomp "--onto --merge --strategy"
664                 return
665         esac
666         __gitcomp "$(__git_refs)"
669 _git_config ()
671         local cur="${COMP_WORDS[COMP_CWORD]}"
672         local prv="${COMP_WORDS[COMP_CWORD-1]}"
673         case "$prv" in
674         branch.*.remote)
675                 __gitcomp "$(__git_remotes)"
676                 return
677                 ;;
678         branch.*.merge)
679                 __gitcomp "$(__git_refs)"
680                 return
681                 ;;
682         remote.*.fetch)
683                 local remote="${prv#remote.}"
684                 remote="${remote%.fetch}"
685                 __gitcomp "$(__git_refs_remotes "$remote")"
686                 return
687                 ;;
688         remote.*.push)
689                 local remote="${prv#remote.}"
690                 remote="${remote%.push}"
691                 __gitcomp "$(git --git-dir="$(__gitdir)" \
692                         for-each-ref --format='%(refname):%(refname)' \
693                         refs/heads)"
694                 return
695                 ;;
696         pull.twohead|pull.octopus)
697                 __gitcomp "$(__git_merge_strategies)"
698                 return
699                 ;;
700         color.branch|color.diff|color.status)
701                 __gitcomp "always never auto"
702                 return
703                 ;;
704         color.*.*)
705                 __gitcomp "
706                         black red green yellow blue magenta cyan white
707                         bold dim ul blink reverse
708                         "
709                 return
710                 ;;
711         *.*)
712                 COMPREPLY=()
713                 return
714                 ;;
715         esac
716         case "$cur" in
717         --*)
718                 __gitcomp "
719                         --global --list --replace-all
720                         --get --get-all --get-regexp
721                         --unset --unset-all
722                         "
723                 return
724                 ;;
725         branch.*.*)
726                 local pfx="${cur%.*}."
727                 cur="${cur##*.}"
728                 __gitcomp "remote merge" "$pfx" "$cur"
729                 return
730                 ;;
731         branch.*)
732                 local pfx="${cur%.*}."
733                 cur="${cur#*.}"
734                 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
735                 return
736                 ;;
737         remote.*.*)
738                 local pfx="${cur%.*}."
739                 cur="${cur##*.}"
740                 __gitcomp "url fetch push" "$pfx" "$cur"
741                 return
742                 ;;
743         remote.*)
744                 local pfx="${cur%.*}."
745                 cur="${cur#*.}"
746                 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
747                 return
748                 ;;
749         esac
750         __gitcomp "
751                 apply.whitespace
752                 core.fileMode
753                 core.gitProxy
754                 core.ignoreStat
755                 core.preferSymlinkRefs
756                 core.logAllRefUpdates
757                 core.repositoryFormatVersion
758                 core.sharedRepository
759                 core.warnAmbiguousRefs
760                 core.compression
761                 core.legacyHeaders
762                 core.packedGitWindowSize
763                 core.packedGitLimit
764                 color.branch
765                 color.branch.current
766                 color.branch.local
767                 color.branch.remote
768                 color.branch.plain
769                 color.diff
770                 color.diff.plain
771                 color.diff.meta
772                 color.diff.frag
773                 color.diff.old
774                 color.diff.new
775                 color.diff.commit
776                 color.diff.whitespace
777                 color.pager
778                 color.status
779                 color.status.header
780                 color.status.added
781                 color.status.changed
782                 color.status.untracked
783                 diff.renameLimit
784                 diff.renames
785                 fetch.unpackLimit
786                 format.headers
787                 gitcvs.enabled
788                 gitcvs.logfile
789                 gc.reflogexpire
790                 gc.reflogexpireunreachable
791                 gc.rerereresolved
792                 gc.rerereunresolved
793                 http.sslVerify
794                 http.sslCert
795                 http.sslKey
796                 http.sslCAInfo
797                 http.sslCAPath
798                 http.maxRequests
799                 http.lowSpeedLimit
800                 http.lowSpeedTime
801                 http.noEPSV
802                 i18n.commitEncoding
803                 i18n.logOutputEncoding
804                 log.showroot
805                 merge.summary
806                 merge.verbosity
807                 pack.window
808                 pull.octopus
809                 pull.twohead
810                 repack.useDeltaBaseOffset
811                 show.difftree
812                 showbranch.default
813                 tar.umask
814                 transfer.unpackLimit
815                 receive.unpackLimit
816                 receive.denyNonFastForwards
817                 user.name
818                 user.email
819                 user.signingkey
820                 whatchanged.difftree
821                 branch. remote.
822         "
825 _git_reset ()
827         local cur="${COMP_WORDS[COMP_CWORD]}"
828         case "$cur" in
829         --*)
830                 __gitcomp "--mixed --hard --soft"
831                 return
832                 ;;
833         esac
834         __gitcomp "$(__git_refs)"
837 _git_show ()
839         local cur="${COMP_WORDS[COMP_CWORD]}"
840         case "$cur" in
841         --pretty=*)
842                 __gitcomp "
843                         oneline short medium full fuller email raw
844                         " "" "${cur##--pretty=}"
845                 return
846                 ;;
847         --*)
848                 __gitcomp "--pretty="
849                 return
850                 ;;
851         esac
852         __git_complete_file
855 _git ()
857         local i c=1 command __git_dir
859         while [ $c -lt $COMP_CWORD ]; do
860                 i="${COMP_WORDS[c]}"
861                 case "$i" in
862                 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
863                 --bare)      __git_dir="." ;;
864                 --version|--help|-p|--paginate) ;;
865                 *) command="$i"; break ;;
866                 esac
867                 c=$((++c))
868         done
870         if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
871                 case "${COMP_WORDS[COMP_CWORD]}" in
872                 --*=*) COMPREPLY=() ;;
873                 --*)   __gitcomp "--git-dir= --bare --version --exec-path" ;;
874                 *)     __gitcomp "$(__git_commands) $(__git_aliases)" ;;
875                 esac
876                 return
877         fi
879         local expansion=$(__git_aliased_command "$command")
880         [ "$expansion" ] && command="$expansion"
882         case "$command" in
883         am)          _git_am ;;
884         add)         _git_add ;;
885         apply)       _git_apply ;;
886         branch)      _git_branch ;;
887         checkout)    _git_checkout ;;
888         cherry)      _git_cherry ;;
889         cherry-pick) _git_cherry_pick ;;
890         commit)      _git_commit ;;
891         config)      _git_config ;;
892         diff)        _git_diff ;;
893         diff-tree)   _git_diff_tree ;;
894         fetch)       _git_fetch ;;
895         format-patch) _git_format_patch ;;
896         gc)          _git_gc ;;
897         log)         _git_log ;;
898         ls-remote)   _git_ls_remote ;;
899         ls-tree)     _git_ls_tree ;;
900         merge)       _git_merge;;
901         merge-base)  _git_merge_base ;;
902         name-rev)    _git_name_rev ;;
903         pull)        _git_pull ;;
904         push)        _git_push ;;
905         rebase)      _git_rebase ;;
906         reset)       _git_reset ;;
907         show)        _git_show ;;
908         show-branch) _git_log ;;
909         whatchanged) _git_log ;;
910         *)           COMPREPLY=() ;;
911         esac
914 _gitk ()
916         local cur="${COMP_WORDS[COMP_CWORD]}"
917         case "$cur" in
918         --*)
919                 __gitcomp "--not --all"
920                 return
921                 ;;
922         esac
923         __git_complete_revlist
926 complete -o default -o nospace -F _git git
927 complete -o default -o nospace -F _gitk gitk
928 complete -o default -o nospace -F _git_am git-am
929 complete -o default -o nospace -F _git_apply git-apply
930 complete -o default -o nospace -F _git_branch git-branch
931 complete -o default -o nospace -F _git_checkout git-checkout
932 complete -o default -o nospace -F _git_cherry git-cherry
933 complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
934 complete -o default -o nospace -F _git_commit git-commit
935 complete -o default -o nospace -F _git_diff git-diff
936 complete -o default -o nospace -F _git_diff_tree git-diff-tree
937 complete -o default -o nospace -F _git_fetch git-fetch
938 complete -o default -o nospace -F _git_format_patch git-format-patch
939 complete -o default -o nospace -F _git_gc git-gc
940 complete -o default -o nospace -F _git_log git-log
941 complete -o default -o nospace -F _git_ls_remote git-ls-remote
942 complete -o default -o nospace -F _git_ls_tree git-ls-tree
943 complete -o default -o nospace -F _git_merge git-merge
944 complete -o default -o nospace -F _git_merge_base git-merge-base
945 complete -o default -o nospace -F _git_name_rev git-name-rev
946 complete -o default -o nospace -F _git_pull git-pull
947 complete -o default -o nospace -F _git_push git-push
948 complete -o default -o nospace -F _git_rebase git-rebase
949 complete -o default -o nospace -F _git_config git-config
950 complete -o default -o nospace -F _git_reset git-reset
951 complete -o default -o nospace -F _git_show git-show
952 complete -o default -o nospace -F _git_log git-show-branch
953 complete -o default -o nospace -F _git_log git-whatchanged
955 # The following are necessary only for Cygwin, and only are needed
956 # when the user has tab-completed the executable name and consequently
957 # included the '.exe' suffix.
959 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
960 complete -o default -o nospace -F _git_add git-add.exe
961 complete -o default -o nospace -F _git_apply git-apply.exe
962 complete -o default -o nospace -F _git git.exe
963 complete -o default -o nospace -F _git_branch git-branch.exe
964 complete -o default -o nospace -F _git_cherry git-cherry.exe
965 complete -o default -o nospace -F _git_diff git-diff.exe
966 complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
967 complete -o default -o nospace -F _git_format_patch git-format-patch.exe
968 complete -o default -o nospace -F _git_log git-log.exe
969 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
970 complete -o default -o nospace -F _git_merge_base git-merge-base.exe
971 complete -o default -o nospace -F _git_name_rev git-name-rev.exe
972 complete -o default -o nospace -F _git_push git-push.exe
973 complete -o default -o nospace -F _git_config git-config
974 complete -o default -o nospace -F _git_show git-show.exe
975 complete -o default -o nospace -F _git_log git-show-branch.exe
976 complete -o default -o nospace -F _git_log git-whatchanged.exe
977 fi