Skip to content

Commit 1eb7e2f

Browse files
lmarlowgitster
authored andcommitted
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>
1 parent 6bb9e51 commit 1eb7e2f

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

contrib/completion/git-completion.bash

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,32 @@ __git_complete_revlist ()
349349
esac
350350
}
351351

352-
__git_commands ()
352+
__git_all_commands ()
353353
{
354-
if [ -n "$__git_commandlist" ]; then
355-
echo "$__git_commandlist"
354+
if [ -n "$__git_all_commandlist" ]; then
355+
echo "$__git_all_commandlist"
356356
return
357357
fi
358358
local i IFS=" "$'\n'
359359
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)
360378
do
361379
case $i in
362380
*--*) : helper pattern;;
@@ -427,8 +445,8 @@ __git_commands ()
427445
esac
428446
done
429447
}
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)"
432450

433451
__git_aliases ()
434452
{
@@ -778,6 +796,18 @@ _git_gc ()
778796
COMPREPLY=()
779797
}
780798

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+
781811
_git_ls_remote ()
782812
{
783813
__gitcomp "$(__git_remotes)"
@@ -1410,7 +1440,8 @@ _git ()
14101440
case "$i" in
14111441
--git-dir=*) __git_dir="${i#--git-dir=}" ;;
14121442
--bare) __git_dir="." ;;
1413-
--version|--help|-p|--paginate) ;;
1443+
--version|-p|--paginate) ;;
1444+
--help) command="help"; break ;;
14141445
*) command="$i"; break ;;
14151446
esac
14161447
c=$((++c))
@@ -1430,7 +1461,7 @@ _git ()
14301461
--help
14311462
"
14321463
;;
1433-
*) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
1464+
*) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
14341465
esac
14351466
return
14361467
fi
@@ -1455,6 +1486,7 @@ _git ()
14551486
fetch) _git_fetch ;;
14561487
format-patch) _git_format_patch ;;
14571488
gc) _git_gc ;;
1489+
help) _git_help ;;
14581490
log) _git_log ;;
14591491
ls-remote) _git_ls_remote ;;
14601492
ls-tree) _git_ls_tree ;;

0 commit comments

Comments
 (0)