bash: Support unique completion on git-config.
[git/git.git] / contrib / completion / git-completion.bash
CommitLineData
690d8824
JH
1#
2# bash completion support for core Git.
3#
2e3a430a 4# Copyright (C) 2006,2007 Shawn Pearce
690d8824
JH
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#
b51ec6bd
SP
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:
d3d717a4
SP
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#
690d8824 34
873537fa
SP
35__gitdir ()
36{
67ffa114
SP
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
873537fa
SP
50}
51
d3d717a4
SP
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}
63
72e5e989
SP
64__gitcomp ()
65{
66 local all c s=$'\n' IFS=' '$'\t'$'\n'
78d4d6a2
SP
67 local cur="${COMP_WORDS[COMP_CWORD]}"
68 if [ -n "$2" ]; then
69 cur="$3"
70 fi
72e5e989 71 for c in $1; do
78d4d6a2
SP
72 case "$c$4" in
73 --*=*) all="$all$c$4$s" ;;
74 *.) all="$all$c$4$s" ;;
75 *) all="$all$c$4 $s" ;;
72e5e989
SP
76 esac
77 done
78 IFS=$s
78d4d6a2 79 COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
72e5e989
SP
80 return
81}
82
5de40f59
SP
83__git_heads ()
84{
67ffa114 85 local cmd i is_hash=y dir="$(__gitdir "$1")"
5de40f59
SP
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
67ffa114 94 for i in $(git-ls-remote "$1" 2>/dev/null); do
5de40f59
SP
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
102}
103
690d8824
JH
104__git_refs ()
105{
67ffa114 106 local cmd i is_hash=y dir="$(__gitdir "$1")"
873537fa 107 if [ -d "$dir" ]; then
35e65ecc
SP
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
690d8824 120 fi
35e65ecc 121 for i in $(git-ls-remote "$dir" 2>/dev/null); do
690d8824
JH
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/}" ;;
35e65ecc 127 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
690d8824
JH
128 n,*) is_hash=y; echo "$i" ;;
129 esac
130 done
131}
132
133__git_refs2 ()
134{
67ffa114
SP
135 local i
136 for i in $(__git_refs "$1"); do
137 echo "$i:$i"
690d8824
JH
138 done
139}
140
5de40f59
SP
141__git_refs_remotes ()
142{
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
156}
157
690d8824
JH
158__git_remotes ()
159{
873537fa 160 local i ngoff IFS=$'\n' d="$(__gitdir)"
56fc25f2 161 shopt -q nullglob || ngoff=1
690d8824 162 shopt -s nullglob
873537fa
SP
163 for i in "$d/remotes"/*; do
164 echo ${i#$d/remotes/}
690d8824 165 done
56fc25f2 166 [ "$ngoff" ] && shopt -u nullglob
e0d10e1c 167 for i in $(git --git-dir="$d" config --list); do
56fc25f2
SP
168 case "$i" in
169 remote.*.url=*)
170 i="${i#remote.}"
171 echo "${i/.url=*/}"
172 ;;
173 esac
174 done
690d8824
JH
175}
176
4ad91321
SP
177__git_merge_strategies ()
178{
b51ec6bd
SP
179 if [ -n "$__git_merge_strategylist" ]; then
180 echo "$__git_merge_strategylist"
181 return
182 fi
4ad91321
SP
183 sed -n "/^all_strategies='/{
184 s/^all_strategies='//
185 s/'//
186 p
187 q
188 }" "$(git --exec-path)/git-merge"
189}
b51ec6bd
SP
190__git_merge_strategylist=
191__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
4ad91321 192
690d8824
JH
193__git_complete_file ()
194{
a79c6551 195 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
690d8824
JH
196 case "$cur" in
197 ?*:*)
a79c6551
SP
198 ref="${cur%%:*}"
199 cur="${cur#*:}"
690d8824
JH
200 case "$cur" in
201 ?*/*)
a79c6551
SP
202 pfx="${cur%/*}"
203 cur="${cur##*/}"
690d8824
JH
204 ls="$ref:$pfx"
205 pfx="$pfx/"
206 ;;
207 *)
208 ls="$ref"
209 ;;
210 esac
211 COMPREPLY=($(compgen -P "$pfx" \
873537fa 212 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
690d8824
JH
213 | sed '/^100... blob /s,^.* ,,
214 /^040000 tree /{
215 s,^.* ,,
216 s,$,/,
217 }
218 s/^.* //')" \
219 -- "$cur"))
220 ;;
221 *)
873537fa 222 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
690d8824
JH
223 ;;
224 esac
225}
226
f53352fb
SP
227__git_complete_revlist ()
228{
229 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
230 case "$cur" in
231 *...*)
232 pfx="${cur%...*}..."
233 cur="${cur#*...}"
234 COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
235 ;;
236 *..*)
237 pfx="${cur%..*}.."
238 cur="${cur#*..}"
239 COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
240 ;;
241 *)
242 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
243 ;;
244 esac
245}
246
f2bb9f88
SP
247__git_commands ()
248{
b51ec6bd
SP
249 if [ -n "$__git_commandlist" ]; then
250 echo "$__git_commandlist"
251 return
252 fi
f2bb9f88
SP
253 local i IFS=" "$'\n'
254 for i in $(git help -a|egrep '^ ')
255 do
256 case $i in
8435b548 257 add--interactive) : plumbing;;
a925c6f1
SP
258 applymbox) : ask gittus;;
259 applypatch) : ask gittus;;
260 archimport) : import;;
2e3a430a 261 cat-file) : plumbing;;
f2bb9f88
SP
262 check-ref-format) : plumbing;;
263 commit-tree) : plumbing;;
264 convert-objects) : plumbing;;
a925c6f1
SP
265 cvsexportcommit) : export;;
266 cvsimport) : import;;
f2bb9f88
SP
267 cvsserver) : daemon;;
268 daemon) : daemon;;
a925c6f1 269 fsck-objects) : plumbing;;
f2bb9f88 270 fetch-pack) : plumbing;;
a925c6f1 271 fmt-merge-msg) : plumbing;;
f2bb9f88
SP
272 hash-object) : plumbing;;
273 http-*) : transport;;
274 index-pack) : plumbing;;
a925c6f1 275 init-db) : deprecated;;
f2bb9f88
SP
276 local-fetch) : plumbing;;
277 mailinfo) : plumbing;;
278 mailsplit) : plumbing;;
279 merge-*) : plumbing;;
280 mktree) : plumbing;;
281 mktag) : plumbing;;
282 pack-objects) : plumbing;;
283 pack-redundant) : plumbing;;
284 pack-refs) : plumbing;;
285 parse-remote) : plumbing;;
286 patch-id) : plumbing;;
287 peek-remote) : plumbing;;
a925c6f1
SP
288 prune) : plumbing;;
289 prune-packed) : plumbing;;
290 quiltimport) : import;;
f2bb9f88
SP
291 read-tree) : plumbing;;
292 receive-pack) : plumbing;;
2e3a430a 293 reflog) : plumbing;;
a925c6f1 294 repo-config) : plumbing;;
f2bb9f88
SP
295 rerere) : plumbing;;
296 rev-list) : plumbing;;
297 rev-parse) : plumbing;;
298 runstatus) : plumbing;;
299 sh-setup) : internal;;
300 shell) : daemon;;
301 send-pack) : plumbing;;
302 show-index) : plumbing;;
303 ssh-*) : transport;;
304 stripspace) : plumbing;;
a925c6f1
SP
305 svn) : import export;;
306 svnimport) : import;;
f2bb9f88 307 symbolic-ref) : plumbing;;
a925c6f1 308 tar-tree) : deprecated;;
f2bb9f88
SP
309 unpack-file) : plumbing;;
310 unpack-objects) : plumbing;;
a925c6f1 311 update-index) : plumbing;;
f2bb9f88
SP
312 update-ref) : plumbing;;
313 update-server-info) : daemon;;
314 upload-archive) : plumbing;;
315 upload-pack) : plumbing;;
316 write-tree) : plumbing;;
a925c6f1 317 verify-tag) : plumbing;;
f2bb9f88
SP
318 *) echo $i;;
319 esac
320 done
321}
b51ec6bd
SP
322__git_commandlist=
323__git_commandlist="$(__git_commands 2>/dev/null)"
f2bb9f88 324
367dce2a
DS
325__git_aliases ()
326{
56fc25f2 327 local i IFS=$'\n'
e0d10e1c 328 for i in $(git --git-dir="$(__gitdir)" config --list); do
56fc25f2
SP
329 case "$i" in
330 alias.*)
331 i="${i#alias.}"
332 echo "${i/=*/}"
333 ;;
334 esac
335 done
367dce2a
DS
336}
337
338__git_aliased_command ()
339{
873537fa 340 local word cmdline=$(git --git-dir="$(__gitdir)" \
e0d10e1c 341 config --get "alias.$1")
367dce2a
DS
342 for word in $cmdline; do
343 if [ "${word##-*}" ]; then
344 echo $word
345 return
346 fi
347 done
348}
349
88329195
SP
350__git_whitespacelist="nowarn warn error error-all strip"
351
352_git_am ()
353{
354 local cur="${COMP_WORDS[COMP_CWORD]}"
355 if [ -d .dotest ]; then
356 COMPREPLY=($(compgen -W "
357 --skip --resolved
358 " -- "$cur"))
359 return
360 fi
361 case "$cur" in
362 --whitespace=*)
363 COMPREPLY=($(compgen -W "$__git_whitespacelist" \
364 -- "${cur##--whitespace=}"))
365 return
366 ;;
367 --*)
368 COMPREPLY=($(compgen -W "
369 --signoff --utf8 --binary --3way --interactive
370 --whitespace=
371 " -- "$cur"))
372 return
373 esac
374 COMPREPLY=()
375}
376
377_git_apply ()
378{
379 local cur="${COMP_WORDS[COMP_CWORD]}"
380 case "$cur" in
381 --whitespace=*)
382 COMPREPLY=($(compgen -W "$__git_whitespacelist" \
383 -- "${cur##--whitespace=}"))
384 return
385 ;;
386 --*)
387 COMPREPLY=($(compgen -W "
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 " -- "$cur"))
393 return
394 esac
395 COMPREPLY=()
396}
397
8435b548
SP
398_git_add ()
399{
400 local cur="${COMP_WORDS[COMP_CWORD]}"
401 case "$cur" in
402 --*)
403 COMPREPLY=($(compgen -W "
404 --interactive
405 " -- "$cur"))
406 return
407 esac
408 COMPREPLY=()
409}
410
690d8824
JH
411_git_branch ()
412{
413 local cur="${COMP_WORDS[COMP_CWORD]}"
9f4cc6f7 414 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
690d8824
JH
415}
416
690d8824
JH
417_git_checkout ()
418{
419 local cur="${COMP_WORDS[COMP_CWORD]}"
9f4cc6f7 420 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
690d8824
JH
421}
422
1273231e
SP
423_git_cherry_pick ()
424{
425 local cur="${COMP_WORDS[COMP_CWORD]}"
426 case "$cur" in
427 --*)
428 COMPREPLY=($(compgen -W "
429 --edit --no-commit
430 " -- "$cur"))
431 ;;
432 *)
433 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
434 ;;
435 esac
436}
437
4548e855
SP
438_git_commit ()
439{
440 local cur="${COMP_WORDS[COMP_CWORD]}"
441 case "$cur" in
442 --*)
443 COMPREPLY=($(compgen -W "
444 --all --author= --signoff --verify --no-verify
445 --edit --amend --include --only
446 " -- "$cur"))
447 return
448 esac
449 COMPREPLY=()
450}
451
690d8824
JH
452_git_diff ()
453{
454 __git_complete_file
455}
456
457_git_diff_tree ()
458{
459 local cur="${COMP_WORDS[COMP_CWORD]}"
9f4cc6f7 460 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
690d8824
JH
461}
462
463_git_fetch ()
464{
465 local cur="${COMP_WORDS[COMP_CWORD]}"
466
467 case "${COMP_WORDS[0]},$COMP_CWORD" in
468 git-fetch*,1)
469 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
470 ;;
471 git,2)
472 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
473 ;;
474 *)
475 case "$cur" in
476 *:*)
a79c6551 477 cur="${cur#*:}"
873537fa 478 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
690d8824
JH
479 ;;
480 *)
481 local remote
482 case "${COMP_WORDS[0]}" in
483 git-fetch) remote="${COMP_WORDS[1]}" ;;
484 git) remote="${COMP_WORDS[2]}" ;;
485 esac
486 COMPREPLY=($(compgen -W "$(__git_refs2 "$remote")" -- "$cur"))
487 ;;
488 esac
489 ;;
490 esac
491}
492
f53352fb
SP
493_git_format_patch ()
494{
495 local cur="${COMP_WORDS[COMP_CWORD]}"
496 case "$cur" in
497 --*)
498 COMPREPLY=($(compgen -W "
499 --stdout --attach --thread
500 --output-directory
501 --numbered --start-number
502 --keep-subject
503 --signoff
504 --in-reply-to=
505 --full-index --binary
506 " -- "$cur"))
507 return
508 ;;
509 esac
510 __git_complete_revlist
511}
512
690d8824
JH
513_git_ls_remote ()
514{
515 local cur="${COMP_WORDS[COMP_CWORD]}"
516 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
517}
518
519_git_ls_tree ()
520{
521 __git_complete_file
522}
523
524_git_log ()
525{
6e31b866
SP
526 local cur="${COMP_WORDS[COMP_CWORD]}"
527 case "$cur" in
528 --pretty=*)
529 COMPREPLY=($(compgen -W "
530 oneline short medium full fuller email raw
531 " -- "${cur##--pretty=}"))
532 return
533 ;;
534 --*)
535 COMPREPLY=($(compgen -W "
536 --max-count= --max-age= --since= --after=
537 --min-age= --before= --until=
538 --root --not --topo-order --date-order
539 --no-merges
540 --abbrev-commit --abbrev=
541 --relative-date
542 --author= --committer= --grep=
543 --all-match
544 --pretty= --name-status --name-only
545 " -- "$cur"))
546 return
547 ;;
548 esac
f53352fb 549 __git_complete_revlist
690d8824
JH
550}
551
4ad91321
SP
552_git_merge ()
553{
554 local cur="${COMP_WORDS[COMP_CWORD]}"
ce1e39d2
SP
555 case "${COMP_WORDS[COMP_CWORD-1]}" in
556 -s|--strategy)
557 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
558 return
559 esac
4ad91321 560 case "$cur" in
ce1e39d2
SP
561 --strategy=*)
562 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
563 -- "${cur##--strategy=}"))
564 return
565 ;;
4ad91321
SP
566 --*)
567 COMPREPLY=($(compgen -W "
61d926a3 568 --no-commit --no-summary --squash --strategy
4ad91321
SP
569 " -- "$cur"))
570 return
571 esac
61d926a3 572 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
4ad91321
SP
573}
574
690d8824
JH
575_git_merge_base ()
576{
577 local cur="${COMP_WORDS[COMP_CWORD]}"
873537fa 578 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
690d8824
JH
579}
580
d33909bf
SP
581_git_name_rev ()
582{
583 local cur="${COMP_WORDS[COMP_CWORD]}"
584 COMPREPLY=($(compgen -W "--tags --all --stdin" -- "$cur"))
585}
586
690d8824
JH
587_git_pull ()
588{
589 local cur="${COMP_WORDS[COMP_CWORD]}"
590
591 case "${COMP_WORDS[0]},$COMP_CWORD" in
592 git-pull*,1)
593 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
594 ;;
595 git,2)
596 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
597 ;;
598 *)
599 local remote
600 case "${COMP_WORDS[0]}" in
601 git-pull) remote="${COMP_WORDS[1]}" ;;
602 git) remote="${COMP_WORDS[2]}" ;;
603 esac
604 COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
605 ;;
606 esac
607}
608
609_git_push ()
610{
611 local cur="${COMP_WORDS[COMP_CWORD]}"
612
613 case "${COMP_WORDS[0]},$COMP_CWORD" in
614 git-push*,1)
615 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
616 ;;
617 git,2)
618 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
619 ;;
620 *)
621 case "$cur" in
622 *:*)
623 local remote
624 case "${COMP_WORDS[0]}" in
625 git-push) remote="${COMP_WORDS[1]}" ;;
626 git) remote="${COMP_WORDS[2]}" ;;
627 esac
a79c6551 628 cur="${cur#*:}"
690d8824
JH
629 COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
630 ;;
631 *)
873537fa 632 COMPREPLY=($(compgen -W "$(__git_refs2)" -- "$cur"))
690d8824
JH
633 ;;
634 esac
635 ;;
636 esac
637}
638
61d926a3
SP
639_git_rebase ()
640{
641 local cur="${COMP_WORDS[COMP_CWORD]}"
642 if [ -d .dotest ]; then
643 COMPREPLY=($(compgen -W "
644 --continue --skip --abort
645 " -- "$cur"))
646 return
647 fi
ce1e39d2
SP
648 case "${COMP_WORDS[COMP_CWORD-1]}" in
649 -s|--strategy)
650 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
651 return
652 esac
61d926a3 653 case "$cur" in
ce1e39d2
SP
654 --strategy=*)
655 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
656 -- "${cur##--strategy=}"))
657 return
658 ;;
61d926a3
SP
659 --*)
660 COMPREPLY=($(compgen -W "
661 --onto --merge --strategy
662 " -- "$cur"))
663 return
664 esac
61d926a3
SP
665 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
666}
667
e0d10e1c 668_git_config ()
5de40f59
SP
669{
670 local cur="${COMP_WORDS[COMP_CWORD]}"
671 local prv="${COMP_WORDS[COMP_CWORD-1]}"
672 case "$prv" in
673 branch.*.remote)
78d4d6a2 674 __gitcomp "$(__git_remotes)"
5de40f59
SP
675 return
676 ;;
677 branch.*.merge)
78d4d6a2 678 __gitcomp "$(__git_refs)"
5de40f59
SP
679 return
680 ;;
681 remote.*.fetch)
682 local remote="${prv#remote.}"
683 remote="${remote%.fetch}"
78d4d6a2 684 __gitcomp "$(__git_refs_remotes "$remote")"
5de40f59
SP
685 return
686 ;;
687 remote.*.push)
688 local remote="${prv#remote.}"
689 remote="${remote%.push}"
78d4d6a2 690 __gitcomp "$(git --git-dir="$(__gitdir)" \
5de40f59 691 for-each-ref --format='%(refname):%(refname)' \
78d4d6a2
SP
692 refs/heads)"
693 return
694 ;;
695 pull.twohead|pull.octopus)
696 __gitcomp "$(__git_merge_strategies)"
697 return
698 ;;
699 color.branch|color.diff|color.status)
700 __gitcomp "always never auto"
701 return
702 ;;
703 color.*.*)
704 __gitcomp "
705 black red green yellow blue magenta cyan white
706 bold dim ul blink reverse
707 "
5de40f59
SP
708 return
709 ;;
710 *.*)
711 COMPREPLY=()
712 return
713 ;;
714 esac
715 case "$cur" in
716 --*)
78d4d6a2 717 __gitcomp "
5de40f59
SP
718 --global --list --replace-all
719 --get --get-all --get-regexp
720 --unset --unset-all
78d4d6a2 721 "
5de40f59
SP
722 return
723 ;;
724 branch.*.*)
725 local pfx="${cur%.*}."
726 cur="${cur##*.}"
78d4d6a2 727 __gitcomp "remote merge" "$pfx" "$cur"
5de40f59
SP
728 return
729 ;;
730 branch.*)
731 local pfx="${cur%.*}."
732 cur="${cur#*.}"
78d4d6a2 733 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
5de40f59
SP
734 return
735 ;;
736 remote.*.*)
737 local pfx="${cur%.*}."
738 cur="${cur##*.}"
78d4d6a2 739 __gitcomp "url fetch push" "$pfx" "$cur"
5de40f59
SP
740 return
741 ;;
742 remote.*)
743 local pfx="${cur%.*}."
744 cur="${cur#*.}"
78d4d6a2 745 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
5de40f59
SP
746 return
747 ;;
748 esac
78d4d6a2 749 __gitcomp "
5de40f59
SP
750 apply.whitespace
751 core.fileMode
752 core.gitProxy
753 core.ignoreStat
754 core.preferSymlinkRefs
755 core.logAllRefUpdates
756 core.repositoryFormatVersion
757 core.sharedRepository
758 core.warnAmbiguousRefs
759 core.compression
760 core.legacyHeaders
78d4d6a2
SP
761 core.packedGitWindowSize
762 core.packedGitLimit
763 color.branch
764 color.branch.current
765 color.branch.local
766 color.branch.remote
767 color.branch.plain
a159ca0c 768 color.diff
78d4d6a2
SP
769 color.diff.plain
770 color.diff.meta
771 color.diff.frag
772 color.diff.old
773 color.diff.new
774 color.diff.commit
775 color.diff.whitespace
a159ca0c 776 color.pager
a159ca0c 777 color.status
78d4d6a2
SP
778 color.status.header
779 color.status.added
780 color.status.changed
781 color.status.untracked
782 diff.renameLimit
783 diff.renames
784 fetch.unpackLimit
785 format.headers
786 gitcvs.enabled
787 gitcvs.logfile
788 gc.reflogexpire
789 gc.reflogexpireunreachable
790 gc.rerereresolved
791 gc.rerereunresolved
5de40f59
SP
792 http.sslVerify
793 http.sslCert
794 http.sslKey
795 http.sslCAInfo
796 http.sslCAPath
797 http.maxRequests
78d4d6a2
SP
798 http.lowSpeedLimit
799 http.lowSpeedTime
5de40f59 800 http.noEPSV
78d4d6a2
SP
801 i18n.commitEncoding
802 i18n.logOutputEncoding
803 log.showroot
804 merge.summary
805 merge.verbosity
5de40f59 806 pack.window
78d4d6a2
SP
807 pull.octopus
808 pull.twohead
5de40f59 809 repack.useDeltaBaseOffset
78d4d6a2
SP
810 show.difftree
811 showbranch.default
812 tar.umask
813 transfer.unpackLimit
5de40f59
SP
814 receive.unpackLimit
815 receive.denyNonFastForwards
78d4d6a2
SP
816 user.name
817 user.email
818 user.signingkey
819 whatchanged.difftree
5de40f59 820 branch. remote.
78d4d6a2 821 "
5de40f59
SP
822}
823
67e78c3b
SP
824_git_reset ()
825{
826 local cur="${COMP_WORDS[COMP_CWORD]}"
827 local opt="--mixed --hard --soft"
873537fa 828 COMPREPLY=($(compgen -W "$opt $(__git_refs)" -- "$cur"))
67e78c3b
SP
829}
830
90131924
SP
831_git_show ()
832{
833 local cur="${COMP_WORDS[COMP_CWORD]}"
834 case "$cur" in
835 --pretty=*)
836 COMPREPLY=($(compgen -W "
837 oneline short medium full fuller email raw
838 " -- "${cur##--pretty=}"))
839 return
840 ;;
841 --*)
842 COMPREPLY=($(compgen -W "--pretty=" -- "$cur"))
843 return
844 ;;
845 esac
846 __git_complete_file
847}
848
690d8824
JH
849_git ()
850{
873537fa
SP
851 local i c=1 command __git_dir
852
853 while [ $c -lt $COMP_CWORD ]; do
854 i="${COMP_WORDS[c]}"
855 case "$i" in
856 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
857 --bare) __git_dir="." ;;
858 --version|--help|-p|--paginate) ;;
859 *) command="$i"; break ;;
860 esac
861 c=$((++c))
862 done
863
864 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
72e5e989
SP
865 case "${COMP_WORDS[COMP_CWORD]}" in
866 --*=*) COMPREPLY=() ;;
867 --*) __gitcomp "--git-dir= --bare --version --exec-path" ;;
868 *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
869 esac
870 return
873537fa 871 fi
367dce2a 872
873537fa
SP
873 local expansion=$(__git_aliased_command "$command")
874 [ "$expansion" ] && command="$expansion"
367dce2a 875
873537fa 876 case "$command" in
88329195 877 am) _git_am ;;
8435b548 878 add) _git_add ;;
88329195 879 apply) _git_apply ;;
873537fa 880 branch) _git_branch ;;
873537fa 881 checkout) _git_checkout ;;
1273231e 882 cherry-pick) _git_cherry_pick ;;
4548e855 883 commit) _git_commit ;;
e0d10e1c 884 config) _git_config ;;
873537fa
SP
885 diff) _git_diff ;;
886 diff-tree) _git_diff_tree ;;
887 fetch) _git_fetch ;;
f53352fb 888 format-patch) _git_format_patch ;;
873537fa
SP
889 log) _git_log ;;
890 ls-remote) _git_ls_remote ;;
891 ls-tree) _git_ls_tree ;;
4ad91321 892 merge) _git_merge;;
873537fa 893 merge-base) _git_merge_base ;;
d33909bf 894 name-rev) _git_name_rev ;;
873537fa
SP
895 pull) _git_pull ;;
896 push) _git_push ;;
61d926a3 897 rebase) _git_rebase ;;
873537fa 898 reset) _git_reset ;;
90131924 899 show) _git_show ;;
873537fa
SP
900 show-branch) _git_log ;;
901 whatchanged) _git_log ;;
902 *) COMPREPLY=() ;;
903 esac
690d8824
JH
904}
905
906_gitk ()
907{
908 local cur="${COMP_WORDS[COMP_CWORD]}"
873537fa 909 COMPREPLY=($(compgen -W "--all $(__git_refs)" -- "$cur"))
690d8824
JH
910}
911
912complete -o default -o nospace -F _git git
913complete -o default -F _gitk gitk
88329195
SP
914complete -o default -F _git_am git-am
915complete -o default -F _git_apply git-apply
690d8824 916complete -o default -F _git_branch git-branch
690d8824 917complete -o default -F _git_checkout git-checkout
1273231e 918complete -o default -F _git_cherry_pick git-cherry-pick
4548e855 919complete -o default -F _git_commit git-commit
690d8824
JH
920complete -o default -o nospace -F _git_diff git-diff
921complete -o default -F _git_diff_tree git-diff-tree
922complete -o default -o nospace -F _git_fetch git-fetch
f53352fb 923complete -o default -o nospace -F _git_format_patch git-format-patch
690d8824
JH
924complete -o default -o nospace -F _git_log git-log
925complete -o default -F _git_ls_remote git-ls-remote
926complete -o default -o nospace -F _git_ls_tree git-ls-tree
4ad91321 927complete -o default -F _git_merge git-merge
690d8824 928complete -o default -F _git_merge_base git-merge-base
d33909bf 929complete -o default -F _git_name_rev git-name-rev
690d8824
JH
930complete -o default -o nospace -F _git_pull git-pull
931complete -o default -o nospace -F _git_push git-push
61d926a3 932complete -o default -F _git_rebase git-rebase
e0d10e1c 933complete -o default -F _git_config git-config
67e78c3b 934complete -o default -F _git_reset git-reset
90131924 935complete -o default -o nospace -F _git_show git-show
144d33de 936complete -o default -o nospace -F _git_log git-show-branch
690d8824
JH
937complete -o default -o nospace -F _git_log git-whatchanged
938
939# The following are necessary only for Cygwin, and only are needed
940# when the user has tab-completed the executable name and consequently
941# included the '.exe' suffix.
942#
76c3eb51 943if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
8435b548 944complete -o default -F _git_add git-add.exe
88329195 945complete -o default -F _git_apply git-apply.exe
144d33de 946complete -o default -o nospace -F _git git.exe
dfb96092 947complete -o default -F _git_branch git-branch.exe
690d8824
JH
948complete -o default -o nospace -F _git_diff git-diff.exe
949complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
f53352fb 950complete -o default -o nospace -F _git_format_patch git-format-patch.exe
690d8824
JH
951complete -o default -o nospace -F _git_log git-log.exe
952complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
953complete -o default -F _git_merge_base git-merge-base.exe
d33909bf 954complete -o default -F _git_name_rev git-name-rev.exe
690d8824 955complete -o default -o nospace -F _git_push git-push.exe
e0d10e1c 956complete -o default -F _git_config git-config
90131924 957complete -o default -o nospace -F _git_show git-show.exe
144d33de 958complete -o default -o nospace -F _git_log git-show-branch.exe
690d8824 959complete -o default -o nospace -F _git_log git-whatchanged.exe
76c3eb51 960fi