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