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