@matheusbsbs / matheus-bagliano / commits / 1eb7e2f834
Fork 0

bash completion: Add completion for 'git help'

Rename cached __git_commandlist to __git_porcelain_commandlist and add __git_all_commandlist that only filters out *--* helpers. Completions for 'git help' will use the __git_all_commandlist, while the __git_porcelain_commandlist is used for git command completion. Users who actually read man pages may want to see help for plumbing commands. Signed-off-by: Lee Marlow <lee.marlow@gmail.com> Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lee Marlow committed Jul 23, 2008 at 18:07 UTC 1eb7e2f83472f49fda62cefe1d2d9b4c668c6771
1 file changed +39 -7
contrib/completion/git-completion.bash
+39 -7
@@ -349,14 +349,32 @@ __git_complete_revlist ()
349 esac
350 }
351
352 -__git_commands ()
352 +__git_all_commands ()
353 {
354 - if [ -n "$__git_commandlist" ]; then
355 - echo "$__git_commandlist"
354 + if [ -n "$__git_all_commandlist" ]; then
355 + echo "$__git_all_commandlist"
356 return
357 fi
358 local i IFS=" "$'\n'
359 for i in $(git help -a|egrep '^ ')
360 + do
361 + case $i in
362 + *--*) : helper pattern;;
363 + *) echo $i;;
364 + esac
365 + done
366 +}
367 +__git_all_commandlist=
368 +__git_all_commandlist="$(__git_all_commands 2>/dev/null)"
369 +
370 +__git_porcelain_commands ()
371 +{
372 + if [ -n "$__git_porcelain_commandlist" ]; then
373 + echo "$__git_porcelain_commandlist"
374 + return
375 + fi
376 + local i IFS=" "$'\n'
377 + for i in "help" $(__git_all_commands)
378 do
379 case $i in
380 *--*) : helper pattern;;
@@ -427,8 +445,8 @@ __git_commands ()
445 esac
446 done
447 }
430 -__git_commandlist=
431 -__git_commandlist="$(__git_commands 2>/dev/null)"
448 +__git_porcelain_commandlist=
449 +__git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
450
451 __git_aliases ()
452 {
@@ -778,6 +796,18 @@ _git_gc ()
796 COMPREPLY=()
797 }
798
799 +_git_help ()
800 +{
801 + local cur="${COMP_WORDS[COMP_CWORD]}"
802 + case "$cur" in
803 + --*)
804 + __gitcomp "--all --info --man --web"
805 + return
806 + ;;
807 + esac
808 + __gitcomp "$(__git_all_commands)"
809 +}
810 +
811 _git_ls_remote ()
812 {
813 __gitcomp "$(__git_remotes)"
@@ -1410,7 +1440,8 @@ _git ()
1440 case "$i" in
1441 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1442 --bare) __git_dir="." ;;
1413 - --version|--help|-p|--paginate) ;;
1443 + --version|-p|--paginate) ;;
1444 + --help) command="help"; break ;;
1445 *) command="$i"; break ;;
1446 esac
1447 c=$((++c))
@@ -1430,7 +1461,7 @@ _git ()
1461 --help
1462 "
1463 ;;
1433 - *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
1464 + *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1465 esac
1466 return
1467 fi
@@ -1455,6 +1486,7 @@ _git ()
1486 fetch) _git_fetch ;;
1487 format-patch) _git_format_patch ;;
1488 gc) _git_gc ;;
1489 + help) _git_help ;;
1490 log) _git_log ;;
1491 ls-remote) _git_ls_remote ;;
1492 ls-tree) _git_ls_tree ;;