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