diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2018-05-20 20:40:08 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-05-21 13:23:14 +0900 |
commit | 3301d36b29467a05107340e4d9688ebf74335021 (patch) | |
tree | 79d2588a177b9c0d77c09b738be9a6b75a877bf7 /contrib/completion | |
parent | e11dca10cfb3ef1e561c3e789b346a9719f0344a (diff) | |
download | git-3301d36b29467a05107340e4d9688ebf74335021.tar.gz |
completion: add and use --list-cmds=alias
By providing aliases via --list-cmds=, we could simplify command
collection code in the script. We only issue one git command. Before
this patch that is "git config", after it's "git --list-cmds=". In
"git help" completion case we actually reduce one "git" process (for
getting guides) but that call was added in this series so it does not
really count.
A couple of bash functions are removed because they are not needed
anymore. __git_compute_all_commands() and $__git_all_commands stay
because they are still needed for completing pager.* config and
without "alias" group, the result is still cacheable.
There is a slight (good) change in _git_help() with this patch: before
"git help <tab>" shows external commands (as in _not_ part of git) as
well as part of $__git_all_commands. We have finer control over
command listing now and can exclude that because we can't provide a
man page for external commands anyway.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/completion')
-rw-r--r-- | contrib/completion/git-completion.bash | 75 |
1 files changed, 15 insertions, 60 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 217c8a3d3b..98f278fb9a 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -834,51 +834,11 @@ __git_complete_strategy () return 1 } -# __git_commands requires 1 argument: -# 1: the command group, either "all" or "porcelain" -__git_commands () { - case "$1" in - porcelain) - if test -n "$GIT_TESTING_PORCELAIN_COMMAND_LIST" - then - printf "%s" "$GIT_TESTING_PORCELAIN_COMMAND_LIST" - else - git --list-cmds=list-mainporcelain,others,nohelpers,list-complete - fi - ;; - all) - if test -n "$GIT_TESTING_ALL_COMMAND_LIST" - then - printf "%s" "$GIT_TESTING_ALL_COMMAND_LIST" - else - git --list-cmds=main,others,nohelpers - fi - ;; - esac -} - -__git_list_all_commands () -{ - __git_commands all -} - __git_all_commands= __git_compute_all_commands () { test -n "$__git_all_commands" || - __git_all_commands=$(__git_list_all_commands) -} - -__git_list_porcelain_commands () -{ - __git_commands porcelain -} - -__git_porcelain_commands= -__git_compute_porcelain_commands () -{ - test -n "$__git_porcelain_commands" || - __git_porcelain_commands=$(__git_list_porcelain_commands) + __git_all_commands=$(git --list-cmds=main,others,alias,nohelpers) } # Lists all set config variables starting with the given section prefix, @@ -896,11 +856,6 @@ __git_pretty_aliases () __git_get_config_variables "pretty" } -__git_aliases () -{ - __git_get_config_variables "alias" -} - # __git_aliased_command requires 1 argument __git_aliased_command () { @@ -1500,13 +1455,6 @@ _git_grep () __git_complete_refs } -__git_all_guides= -__git_compute_all_guides () -{ - test -n "$__git_all_guides" || - __git_all_guides=$(git --list-cmds=list-guide) -} - _git_help () { case "$cur" in @@ -1515,11 +1463,12 @@ _git_help () return ;; esac - __git_compute_all_commands - __git_compute_all_guides - __gitcomp "$__git_all_commands $(__git_aliases) $__git_all_guides - gitk - " + if test -n "$GIT_TESTING_ALL_COMMAND_LIST" + then + __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(git --list-cmds=alias,list-guide) gitk" + else + __gitcomp "$(git --list-cmds=main,nohelpers,alias,list-guide) gitk" + fi } _git_init () @@ -3058,8 +3007,14 @@ __git_main () --help " ;; - *) __git_compute_porcelain_commands - __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;; + *) + if test -n "$GIT_TESTING_PORCELAIN_COMMAND_LIST" + then + __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST" + else + __gitcomp "$(git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete)" + fi + ;; esac return fi |