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