]> git.ipfire.org Git - thirdparty/git.git/blob - contrib/completion/git-completion.bash
Teach bash how to complete long options for git-commit.
[thirdparty/git.git] / contrib / completion / git-completion.bash
1 #
2 # bash completion support for core Git.
3 #
4 # Copyright (C) 2006 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 #
34
35 __gitdir ()
36 {
37 echo "${__git_dir:-$(git rev-parse --git-dir 2>/dev/null)}"
38 }
39
40 __git_ps1 ()
41 {
42 local b="$(git symbolic-ref HEAD 2>/dev/null)"
43 if [ -n "$b" ]; then
44 if [ -n "$1" ]; then
45 printf "$1" "${b##refs/heads/}"
46 else
47 printf " (%s)" "${b##refs/heads/}"
48 fi
49 fi
50 }
51
52 __git_heads ()
53 {
54 local cmd i is_hash=y dir="${1:-$(__gitdir)}"
55 if [ -d "$dir" ]; then
56 for i in $(git --git-dir="$dir" \
57 for-each-ref --format='%(refname)' \
58 refs/heads ); do
59 echo "${i#refs/heads/}"
60 done
61 return
62 fi
63 for i in $(git-ls-remote "$dir" 2>/dev/null); do
64 case "$is_hash,$i" in
65 y,*) is_hash=n ;;
66 n,*^{}) is_hash=y ;;
67 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
68 n,*) is_hash=y; echo "$i" ;;
69 esac
70 done
71 }
72
73 __git_refs ()
74 {
75 local cmd i is_hash=y dir="${1:-$(__gitdir)}"
76 if [ -d "$dir" ]; then
77 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
78 for i in $(git --git-dir="$dir" \
79 for-each-ref --format='%(refname)' \
80 refs/tags refs/heads refs/remotes); do
81 case "$i" in
82 refs/tags/*) echo "${i#refs/tags/}" ;;
83 refs/heads/*) echo "${i#refs/heads/}" ;;
84 refs/remotes/*) echo "${i#refs/remotes/}" ;;
85 *) echo "$i" ;;
86 esac
87 done
88 return
89 fi
90 for i in $(git-ls-remote "$dir" 2>/dev/null); do
91 case "$is_hash,$i" in
92 y,*) is_hash=n ;;
93 n,*^{}) is_hash=y ;;
94 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
95 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
96 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
97 n,*) is_hash=y; echo "$i" ;;
98 esac
99 done
100 }
101
102 __git_refs2 ()
103 {
104 local cmd i is_hash=y dir="${1:-$(__gitdir)}"
105 if [ -d "$dir" ]; then
106 cmd=git-peek-remote
107 else
108 cmd=git-ls-remote
109 fi
110 for i in $($cmd "$dir" 2>/dev/null); do
111 case "$is_hash,$i" in
112 y,*) is_hash=n ;;
113 n,*^{}) is_hash=y ;;
114 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}:${i#refs/tags/}" ;;
115 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}:${i#refs/heads/}" ;;
116 n,*) is_hash=y; echo "$i:$i" ;;
117 esac
118 done
119 }
120
121 __git_refs_remotes ()
122 {
123 local cmd i is_hash=y
124 for i in $(git-ls-remote "$1" 2>/dev/null); do
125 case "$is_hash,$i" in
126 n,refs/heads/*)
127 is_hash=y
128 echo "$i:refs/remotes/$1/${i#refs/heads/}"
129 ;;
130 y,*) is_hash=n ;;
131 n,*^{}) is_hash=y ;;
132 n,refs/tags/*) is_hash=y;;
133 n,*) is_hash=y; ;;
134 esac
135 done
136 }
137
138 __git_remotes ()
139 {
140 local i ngoff IFS=$'\n' d="$(__gitdir)"
141 shopt -q nullglob || ngoff=1
142 shopt -s nullglob
143 for i in "$d/remotes"/*; do
144 echo ${i#$d/remotes/}
145 done
146 [ "$ngoff" ] && shopt -u nullglob
147 for i in $(git --git-dir="$d" repo-config --list); do
148 case "$i" in
149 remote.*.url=*)
150 i="${i#remote.}"
151 echo "${i/.url=*/}"
152 ;;
153 esac
154 done
155 }
156
157 __git_merge_strategies ()
158 {
159 if [ -n "$__git_merge_strategylist" ]; then
160 echo "$__git_merge_strategylist"
161 return
162 fi
163 sed -n "/^all_strategies='/{
164 s/^all_strategies='//
165 s/'//
166 p
167 q
168 }" "$(git --exec-path)/git-merge"
169 }
170 __git_merge_strategylist=
171 __git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
172
173 __git_complete_file ()
174 {
175 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
176 case "$cur" in
177 ?*:*)
178 ref="${cur%%:*}"
179 cur="${cur#*:}"
180 case "$cur" in
181 ?*/*)
182 pfx="${cur%/*}"
183 cur="${cur##*/}"
184 ls="$ref:$pfx"
185 pfx="$pfx/"
186 ;;
187 *)
188 ls="$ref"
189 ;;
190 esac
191 COMPREPLY=($(compgen -P "$pfx" \
192 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
193 | sed '/^100... blob /s,^.* ,,
194 /^040000 tree /{
195 s,^.* ,,
196 s,$,/,
197 }
198 s/^.* //')" \
199 -- "$cur"))
200 ;;
201 *)
202 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
203 ;;
204 esac
205 }
206
207 __git_complete_revlist ()
208 {
209 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
210 case "$cur" in
211 *...*)
212 pfx="${cur%...*}..."
213 cur="${cur#*...}"
214 COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
215 ;;
216 *..*)
217 pfx="${cur%..*}.."
218 cur="${cur#*..}"
219 COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
220 ;;
221 *)
222 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
223 ;;
224 esac
225 }
226
227 __git_commands ()
228 {
229 if [ -n "$__git_commandlist" ]; then
230 echo "$__git_commandlist"
231 return
232 fi
233 local i IFS=" "$'\n'
234 for i in $(git help -a|egrep '^ ')
235 do
236 case $i in
237 check-ref-format) : plumbing;;
238 commit-tree) : plumbing;;
239 convert-objects) : plumbing;;
240 cvsserver) : daemon;;
241 daemon) : daemon;;
242 fetch-pack) : plumbing;;
243 hash-object) : plumbing;;
244 http-*) : transport;;
245 index-pack) : plumbing;;
246 local-fetch) : plumbing;;
247 mailinfo) : plumbing;;
248 mailsplit) : plumbing;;
249 merge-*) : plumbing;;
250 mktree) : plumbing;;
251 mktag) : plumbing;;
252 pack-objects) : plumbing;;
253 pack-redundant) : plumbing;;
254 pack-refs) : plumbing;;
255 parse-remote) : plumbing;;
256 patch-id) : plumbing;;
257 peek-remote) : plumbing;;
258 read-tree) : plumbing;;
259 receive-pack) : plumbing;;
260 rerere) : plumbing;;
261 rev-list) : plumbing;;
262 rev-parse) : plumbing;;
263 runstatus) : plumbing;;
264 sh-setup) : internal;;
265 shell) : daemon;;
266 send-pack) : plumbing;;
267 show-index) : plumbing;;
268 ssh-*) : transport;;
269 stripspace) : plumbing;;
270 symbolic-ref) : plumbing;;
271 unpack-file) : plumbing;;
272 unpack-objects) : plumbing;;
273 update-ref) : plumbing;;
274 update-server-info) : daemon;;
275 upload-archive) : plumbing;;
276 upload-pack) : plumbing;;
277 write-tree) : plumbing;;
278 *) echo $i;;
279 esac
280 done
281 }
282 __git_commandlist=
283 __git_commandlist="$(__git_commands 2>/dev/null)"
284
285 __git_aliases ()
286 {
287 local i IFS=$'\n'
288 for i in $(git --git-dir="$(__gitdir)" repo-config --list); do
289 case "$i" in
290 alias.*)
291 i="${i#alias.}"
292 echo "${i/=*/}"
293 ;;
294 esac
295 done
296 }
297
298 __git_aliased_command ()
299 {
300 local word cmdline=$(git --git-dir="$(__gitdir)" \
301 repo-config --get "alias.$1")
302 for word in $cmdline; do
303 if [ "${word##-*}" ]; then
304 echo $word
305 return
306 fi
307 done
308 }
309
310 __git_whitespacelist="nowarn warn error error-all strip"
311
312 _git_am ()
313 {
314 local cur="${COMP_WORDS[COMP_CWORD]}"
315 if [ -d .dotest ]; then
316 COMPREPLY=($(compgen -W "
317 --skip --resolved
318 " -- "$cur"))
319 return
320 fi
321 case "$cur" in
322 --whitespace=*)
323 COMPREPLY=($(compgen -W "$__git_whitespacelist" \
324 -- "${cur##--whitespace=}"))
325 return
326 ;;
327 --*)
328 COMPREPLY=($(compgen -W "
329 --signoff --utf8 --binary --3way --interactive
330 --whitespace=
331 " -- "$cur"))
332 return
333 esac
334 COMPREPLY=()
335 }
336
337 _git_apply ()
338 {
339 local cur="${COMP_WORDS[COMP_CWORD]}"
340 case "$cur" in
341 --whitespace=*)
342 COMPREPLY=($(compgen -W "$__git_whitespacelist" \
343 -- "${cur##--whitespace=}"))
344 return
345 ;;
346 --*)
347 COMPREPLY=($(compgen -W "
348 --stat --numstat --summary --check --index
349 --cached --index-info --reverse --reject --unidiff-zero
350 --apply --no-add --exclude=
351 --whitespace= --inaccurate-eof --verbose
352 " -- "$cur"))
353 return
354 esac
355 COMPREPLY=()
356 }
357
358 _git_branch ()
359 {
360 local cur="${COMP_WORDS[COMP_CWORD]}"
361 COMPREPLY=($(compgen -W "-l -f -d -D $(__git_refs)" -- "$cur"))
362 }
363
364 _git_cat_file ()
365 {
366 local cur="${COMP_WORDS[COMP_CWORD]}"
367 case "${COMP_WORDS[0]},$COMP_CWORD" in
368 git-cat-file*,1)
369 COMPREPLY=($(compgen -W "-p -t blob tree commit tag" -- "$cur"))
370 ;;
371 git,2)
372 COMPREPLY=($(compgen -W "-p -t blob tree commit tag" -- "$cur"))
373 ;;
374 *)
375 __git_complete_file
376 ;;
377 esac
378 }
379
380 _git_checkout ()
381 {
382 local cur="${COMP_WORDS[COMP_CWORD]}"
383 COMPREPLY=($(compgen -W "-l -b $(__git_refs)" -- "$cur"))
384 }
385
386 _git_cherry_pick ()
387 {
388 local cur="${COMP_WORDS[COMP_CWORD]}"
389 case "$cur" in
390 --*)
391 COMPREPLY=($(compgen -W "
392 --edit --no-commit
393 " -- "$cur"))
394 ;;
395 *)
396 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
397 ;;
398 esac
399 }
400
401 _git_commit ()
402 {
403 local cur="${COMP_WORDS[COMP_CWORD]}"
404 case "$cur" in
405 --*)
406 COMPREPLY=($(compgen -W "
407 --all --author= --signoff --verify --no-verify
408 --edit --amend --include --only
409 " -- "$cur"))
410 return
411 esac
412 COMPREPLY=()
413 }
414
415 _git_diff ()
416 {
417 __git_complete_file
418 }
419
420 _git_diff_tree ()
421 {
422 local cur="${COMP_WORDS[COMP_CWORD]}"
423 COMPREPLY=($(compgen -W "-r -p -M $(__git_refs)" -- "$cur"))
424 }
425
426 _git_fetch ()
427 {
428 local cur="${COMP_WORDS[COMP_CWORD]}"
429
430 case "${COMP_WORDS[0]},$COMP_CWORD" in
431 git-fetch*,1)
432 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
433 ;;
434 git,2)
435 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
436 ;;
437 *)
438 case "$cur" in
439 *:*)
440 cur="${cur#*:}"
441 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
442 ;;
443 *)
444 local remote
445 case "${COMP_WORDS[0]}" in
446 git-fetch) remote="${COMP_WORDS[1]}" ;;
447 git) remote="${COMP_WORDS[2]}" ;;
448 esac
449 COMPREPLY=($(compgen -W "$(__git_refs2 "$remote")" -- "$cur"))
450 ;;
451 esac
452 ;;
453 esac
454 }
455
456 _git_format_patch ()
457 {
458 local cur="${COMP_WORDS[COMP_CWORD]}"
459 case "$cur" in
460 --*)
461 COMPREPLY=($(compgen -W "
462 --stdout --attach --thread
463 --output-directory
464 --numbered --start-number
465 --keep-subject
466 --signoff
467 --in-reply-to=
468 --full-index --binary
469 " -- "$cur"))
470 return
471 ;;
472 esac
473 __git_complete_revlist
474 }
475
476 _git_ls_remote ()
477 {
478 local cur="${COMP_WORDS[COMP_CWORD]}"
479 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
480 }
481
482 _git_ls_tree ()
483 {
484 __git_complete_file
485 }
486
487 _git_log ()
488 {
489 local cur="${COMP_WORDS[COMP_CWORD]}"
490 case "$cur" in
491 --pretty=*)
492 COMPREPLY=($(compgen -W "
493 oneline short medium full fuller email raw
494 " -- "${cur##--pretty=}"))
495 return
496 ;;
497 --*)
498 COMPREPLY=($(compgen -W "
499 --max-count= --max-age= --since= --after=
500 --min-age= --before= --until=
501 --root --not --topo-order --date-order
502 --no-merges
503 --abbrev-commit --abbrev=
504 --relative-date
505 --author= --committer= --grep=
506 --all-match
507 --pretty= --name-status --name-only
508 " -- "$cur"))
509 return
510 ;;
511 esac
512 __git_complete_revlist
513 }
514
515 _git_merge ()
516 {
517 local cur="${COMP_WORDS[COMP_CWORD]}"
518 case "${COMP_WORDS[COMP_CWORD-1]}" in
519 -s|--strategy)
520 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
521 return
522 esac
523 case "$cur" in
524 --strategy=*)
525 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
526 -- "${cur##--strategy=}"))
527 return
528 ;;
529 --*)
530 COMPREPLY=($(compgen -W "
531 --no-commit --no-summary --squash --strategy
532 " -- "$cur"))
533 return
534 esac
535 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
536 }
537
538 _git_merge_base ()
539 {
540 local cur="${COMP_WORDS[COMP_CWORD]}"
541 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
542 }
543
544 _git_name_rev ()
545 {
546 local cur="${COMP_WORDS[COMP_CWORD]}"
547 COMPREPLY=($(compgen -W "--tags --all --stdin" -- "$cur"))
548 }
549
550 _git_pull ()
551 {
552 local cur="${COMP_WORDS[COMP_CWORD]}"
553
554 case "${COMP_WORDS[0]},$COMP_CWORD" in
555 git-pull*,1)
556 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
557 ;;
558 git,2)
559 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
560 ;;
561 *)
562 local remote
563 case "${COMP_WORDS[0]}" in
564 git-pull) remote="${COMP_WORDS[1]}" ;;
565 git) remote="${COMP_WORDS[2]}" ;;
566 esac
567 COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
568 ;;
569 esac
570 }
571
572 _git_push ()
573 {
574 local cur="${COMP_WORDS[COMP_CWORD]}"
575
576 case "${COMP_WORDS[0]},$COMP_CWORD" in
577 git-push*,1)
578 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
579 ;;
580 git,2)
581 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
582 ;;
583 *)
584 case "$cur" in
585 *:*)
586 local remote
587 case "${COMP_WORDS[0]}" in
588 git-push) remote="${COMP_WORDS[1]}" ;;
589 git) remote="${COMP_WORDS[2]}" ;;
590 esac
591 cur="${cur#*:}"
592 COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
593 ;;
594 *)
595 COMPREPLY=($(compgen -W "$(__git_refs2)" -- "$cur"))
596 ;;
597 esac
598 ;;
599 esac
600 }
601
602 _git_rebase ()
603 {
604 local cur="${COMP_WORDS[COMP_CWORD]}"
605 if [ -d .dotest ]; then
606 COMPREPLY=($(compgen -W "
607 --continue --skip --abort
608 " -- "$cur"))
609 return
610 fi
611 case "${COMP_WORDS[COMP_CWORD-1]}" in
612 -s|--strategy)
613 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
614 return
615 esac
616 case "$cur" in
617 --strategy=*)
618 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
619 -- "${cur##--strategy=}"))
620 return
621 ;;
622 --*)
623 COMPREPLY=($(compgen -W "
624 --onto --merge --strategy
625 " -- "$cur"))
626 return
627 esac
628 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
629 }
630
631 _git_repo_config ()
632 {
633 local cur="${COMP_WORDS[COMP_CWORD]}"
634 local prv="${COMP_WORDS[COMP_CWORD-1]}"
635 case "$prv" in
636 branch.*.remote)
637 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
638 return
639 ;;
640 branch.*.merge)
641 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
642 return
643 ;;
644 remote.*.fetch)
645 local remote="${prv#remote.}"
646 remote="${remote%.fetch}"
647 COMPREPLY=($(compgen -W "$(__git_refs_remotes "$remote")" \
648 -- "$cur"))
649 return
650 ;;
651 remote.*.push)
652 local remote="${prv#remote.}"
653 remote="${remote%.push}"
654 COMPREPLY=($(compgen -W "$(git --git-dir="$(__gitdir)" \
655 for-each-ref --format='%(refname):%(refname)' \
656 refs/heads)" -- "$cur"))
657 return
658 ;;
659 *.*)
660 COMPREPLY=()
661 return
662 ;;
663 esac
664 case "$cur" in
665 --*)
666 COMPREPLY=($(compgen -W "
667 --global --list --replace-all
668 --get --get-all --get-regexp
669 --unset --unset-all
670 " -- "$cur"))
671 return
672 ;;
673 branch.*.*)
674 local pfx="${cur%.*}."
675 cur="${cur##*.}"
676 COMPREPLY=($(compgen -P "$pfx" -W "remote merge" -- "$cur"))
677 return
678 ;;
679 branch.*)
680 local pfx="${cur%.*}."
681 cur="${cur#*.}"
682 COMPREPLY=($(compgen -P "$pfx" -S . \
683 -W "$(__git_heads)" -- "$cur"))
684 return
685 ;;
686 remote.*.*)
687 local pfx="${cur%.*}."
688 cur="${cur##*.}"
689 COMPREPLY=($(compgen -P "$pfx" -W "url fetch push" -- "$cur"))
690 return
691 ;;
692 remote.*)
693 local pfx="${cur%.*}."
694 cur="${cur#*.}"
695 COMPREPLY=($(compgen -P "$pfx" -S . \
696 -W "$(__git_remotes)" -- "$cur"))
697 return
698 ;;
699 esac
700 COMPREPLY=($(compgen -W "
701 apply.whitespace
702 core.fileMode
703 core.gitProxy
704 core.ignoreStat
705 core.preferSymlinkRefs
706 core.logAllRefUpdates
707 core.repositoryFormatVersion
708 core.sharedRepository
709 core.warnAmbiguousRefs
710 core.compression
711 core.legacyHeaders
712 i18n.commitEncoding
713 diff.color
714 diff.renameLimit
715 diff.renames
716 pager.color
717 status.color
718 log.showroot
719 show.difftree
720 showbranch.default
721 whatchanged.difftree
722 http.sslVerify
723 http.sslCert
724 http.sslKey
725 http.sslCAInfo
726 http.sslCAPath
727 http.maxRequests
728 http.lowSpeedLimit http.lowSpeedTime
729 http.noEPSV
730 pack.window
731 repack.useDeltaBaseOffset
732 pull.octopus pull.twohead
733 merge.summary
734 receive.unpackLimit
735 receive.denyNonFastForwards
736 user.name user.email
737 tar.umask
738 gitcvs.enabled
739 gitcvs.logfile
740 branch. remote.
741 " -- "$cur"))
742 }
743
744 _git_reset ()
745 {
746 local cur="${COMP_WORDS[COMP_CWORD]}"
747 local opt="--mixed --hard --soft"
748 COMPREPLY=($(compgen -W "$opt $(__git_refs)" -- "$cur"))
749 }
750
751 _git ()
752 {
753 local i c=1 command __git_dir
754
755 while [ $c -lt $COMP_CWORD ]; do
756 i="${COMP_WORDS[c]}"
757 case "$i" in
758 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
759 --bare) __git_dir="." ;;
760 --version|--help|-p|--paginate) ;;
761 *) command="$i"; break ;;
762 esac
763 c=$((++c))
764 done
765
766 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
767 COMPREPLY=($(compgen -W "
768 --git-dir= --version --exec-path
769 $(__git_commands)
770 $(__git_aliases)
771 " -- "${COMP_WORDS[COMP_CWORD]}"))
772 return;
773 fi
774
775 local expansion=$(__git_aliased_command "$command")
776 [ "$expansion" ] && command="$expansion"
777
778 case "$command" in
779 am) _git_am ;;
780 apply) _git_apply ;;
781 branch) _git_branch ;;
782 cat-file) _git_cat_file ;;
783 checkout) _git_checkout ;;
784 cherry-pick) _git_cherry_pick ;;
785 commit) _git_commit ;;
786 diff) _git_diff ;;
787 diff-tree) _git_diff_tree ;;
788 fetch) _git_fetch ;;
789 format-patch) _git_format_patch ;;
790 log) _git_log ;;
791 ls-remote) _git_ls_remote ;;
792 ls-tree) _git_ls_tree ;;
793 merge) _git_merge;;
794 merge-base) _git_merge_base ;;
795 name-rev) _git_name_rev ;;
796 pull) _git_pull ;;
797 push) _git_push ;;
798 rebase) _git_rebase ;;
799 repo-config) _git_repo_config ;;
800 reset) _git_reset ;;
801 show) _git_log ;;
802 show-branch) _git_log ;;
803 whatchanged) _git_log ;;
804 *) COMPREPLY=() ;;
805 esac
806 }
807
808 _gitk ()
809 {
810 local cur="${COMP_WORDS[COMP_CWORD]}"
811 COMPREPLY=($(compgen -W "--all $(__git_refs)" -- "$cur"))
812 }
813
814 complete -o default -o nospace -F _git git
815 complete -o default -F _gitk gitk
816 complete -o default -F _git_am git-am
817 complete -o default -F _git_apply git-apply
818 complete -o default -F _git_branch git-branch
819 complete -o default -o nospace -F _git_cat_file git-cat-file
820 complete -o default -F _git_checkout git-checkout
821 complete -o default -F _git_cherry_pick git-cherry-pick
822 complete -o default -F _git_commit git-commit
823 complete -o default -o nospace -F _git_diff git-diff
824 complete -o default -F _git_diff_tree git-diff-tree
825 complete -o default -o nospace -F _git_fetch git-fetch
826 complete -o default -o nospace -F _git_format_patch git-format-patch
827 complete -o default -o nospace -F _git_log git-log
828 complete -o default -F _git_ls_remote git-ls-remote
829 complete -o default -o nospace -F _git_ls_tree git-ls-tree
830 complete -o default -F _git_merge git-merge
831 complete -o default -F _git_merge_base git-merge-base
832 complete -o default -F _git_name_rev git-name-rev
833 complete -o default -o nospace -F _git_pull git-pull
834 complete -o default -o nospace -F _git_push git-push
835 complete -o default -F _git_rebase git-rebase
836 complete -o default -F _git_repo_config git-repo-config
837 complete -o default -F _git_reset git-reset
838 complete -o default -F _git_log git-show
839 complete -o default -o nospace -F _git_log git-show-branch
840 complete -o default -o nospace -F _git_log git-whatchanged
841
842 # The following are necessary only for Cygwin, and only are needed
843 # when the user has tab-completed the executable name and consequently
844 # included the '.exe' suffix.
845 #
846 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
847 complete -o default -F _git_apply git-apply.exe
848 complete -o default -o nospace -F _git git.exe
849 complete -o default -F _git_branch git-branch.exe
850 complete -o default -o nospace -F _git_cat_file git-cat-file.exe
851 complete -o default -o nospace -F _git_diff git-diff.exe
852 complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
853 complete -o default -o nospace -F _git_format_patch git-format-patch.exe
854 complete -o default -o nospace -F _git_log git-log.exe
855 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
856 complete -o default -F _git_merge_base git-merge-base.exe
857 complete -o default -F _git_name_rev git-name-rev.exe
858 complete -o default -o nospace -F _git_push git-push.exe
859 complete -o default -F _git_repo_config git-repo-config
860 complete -o default -o nospace -F _git_log git-show.exe
861 complete -o default -o nospace -F _git_log git-show-branch.exe
862 complete -o default -o nospace -F _git_log git-whatchanged.exe
863 fi