@matheusbsbs / matheus-bagliano / commits / f53352fbaf
Fork 0

Teach bash how to complete git-format-patch.

Provide completion for currently known long options supported by git-format-patch as well as the revision list specification argument, which is generally either a refname or in the form a..b. Since _git_log was the only code that knew how to complete a..b, but we want to start adding option support to _git_log also refactor the a..b completion logic out into its own function. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed Nov 27, 2006 at 03:41 UTC f53352fbaf2bcc6d209388bb2a68d888ceb8014e
1 file changed +44 -16
contrib/completion/git-completion.bash
+44 -16
@@ -144,6 +144,26 @@ __git_complete_file ()
144 esac
145 }
146
147 +__git_complete_revlist ()
148 +{
149 + local pfx cur="${COMP_WORDS[COMP_CWORD]}"
150 + case "$cur" in
151 + *...*)
152 + pfx="${cur%...*}..."
153 + cur="${cur#*...}"
154 + COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
155 + ;;
156 + *..*)
157 + pfx="${cur%..*}.."
158 + cur="${cur#*..}"
159 + COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
160 + ;;
161 + *)
162 + COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
163 + ;;
164 + esac
165 +}
166 +
167 __git_commands ()
168 {
169 local i IFS=" "$'\n'
@@ -290,6 +310,26 @@ _git_fetch ()
310 esac
311 }
312
313 +_git_format_patch ()
314 +{
315 + local cur="${COMP_WORDS[COMP_CWORD]}"
316 + case "$cur" in
317 + --*)
318 + COMPREPLY=($(compgen -W "
319 + --stdout --attach --thread
320 + --output-directory
321 + --numbered --start-number
322 + --keep-subject
323 + --signoff
324 + --in-reply-to=
325 + --full-index --binary
326 + " -- "$cur"))
327 + return
328 + ;;
329 + esac
330 + __git_complete_revlist
331 +}
332 +
333 _git_ls_remote ()
334 {
335 local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -303,22 +343,7 @@ _git_ls_tree ()
343
344 _git_log ()
345 {
306 - local pfx cur="${COMP_WORDS[COMP_CWORD]}"
307 - case "$cur" in
308 - *...*)
309 - pfx="${cur%...*}..."
310 - cur="${cur#*...}"
311 - COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
312 - ;;
313 - *..*)
314 - pfx="${cur%..*}.."
315 - cur="${cur#*..}"
316 - COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
317 - ;;
318 - *)
319 - COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
320 - ;;
321 - esac
346 + __git_complete_revlist
347 }
348
349 _git_merge ()
@@ -450,6 +475,7 @@ _git ()
475 diff) _git_diff ;;
476 diff-tree) _git_diff_tree ;;
477 fetch) _git_fetch ;;
478 + format-patch) _git_format_patch ;;
479 log) _git_log ;;
480 ls-remote) _git_ls_remote ;;
481 ls-tree) _git_ls_tree ;;
@@ -480,6 +506,7 @@ complete -o default -F _git_checkout git-checkout
506 complete -o default -o nospace -F _git_diff git-diff
507 complete -o default -F _git_diff_tree git-diff-tree
508 complete -o default -o nospace -F _git_fetch git-fetch
509 +complete -o default -o nospace -F _git_format_patch git-format-patch
510 complete -o default -o nospace -F _git_log git-log
511 complete -o default -F _git_ls_remote git-ls-remote
512 complete -o default -o nospace -F _git_ls_tree git-ls-tree
@@ -503,6 +530,7 @@ complete -o default -F _git_branch git-branch.exe
530 complete -o default -o nospace -F _git_cat_file git-cat-file.exe
531 complete -o default -o nospace -F _git_diff git-diff.exe
532 complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
533 +complete -o default -o nospace -F _git_format_patch git-format-patch.exe
534 complete -o default -o nospace -F _git_log git-log.exe
535 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
536 complete -o default -F _git_merge_base git-merge-base.exe