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