Code

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