]> git.ipfire.org Git - thirdparty/git.git/blobdiff - contrib/completion/git-completion.bash
completion: let git provide the completable command list
[thirdparty/git.git] / contrib / completion / git-completion.bash
index a7570739454ac793430b7f0edb8ba229f3ff50d8..cd1d8e553f33ddd8efe4098434aebe245e735b81 100644 (file)
@@ -834,19 +834,33 @@ __git_complete_strategy ()
        return 1
 }
 
+# __git_commands requires 1 argument:
+# 1: the command group, either "all" or "porcelain"
 __git_commands () {
-       if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
-       then
-               printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
-       else
-               git help -a|egrep '^  [a-zA-Z0-9]'
-       fi
+       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,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
+               fi
+               ;;
+       esac
 }
 
-__git_list_all_commands ()
+__git_list_commands ()
 {
        local i IFS=" "$'\n'
-       for i in $(__git_commands)
+       for i in $(__git_commands $1)
        do
                case $i in
                *--*)             : helper pattern;;
@@ -855,6 +869,11 @@ __git_list_all_commands ()
        done
 }
 
+__git_list_all_commands ()
+{
+       __git_list_commands all
+}
+
 __git_all_commands=
 __git_compute_all_commands ()
 {
@@ -864,89 +883,7 @@ __git_compute_all_commands ()
 
 __git_list_porcelain_commands ()
 {
-       local i IFS=" "$'\n'
-       __git_compute_all_commands
-       for i in $__git_all_commands
-       do
-               case $i in
-               *--*)             : helper pattern;;
-               applymbox)        : ask gittus;;
-               applypatch)       : ask gittus;;
-               archimport)       : import;;
-               cat-file)         : plumbing;;
-               check-attr)       : plumbing;;
-               check-ignore)     : plumbing;;
-               check-mailmap)    : plumbing;;
-               check-ref-format) : plumbing;;
-               checkout-index)   : plumbing;;
-               column)           : internal helper;;
-               commit-tree)      : plumbing;;
-               count-objects)    : infrequent;;
-               credential)       : credentials;;
-               credential-*)     : credentials helper;;
-               cvsexportcommit)  : export;;
-               cvsimport)        : import;;
-               cvsserver)        : daemon;;
-               daemon)           : daemon;;
-               diff-files)       : plumbing;;
-               diff-index)       : plumbing;;
-               diff-tree)        : plumbing;;
-               fast-import)      : import;;
-               fast-export)      : export;;
-               fsck-objects)     : plumbing;;
-               fetch-pack)       : plumbing;;
-               fmt-merge-msg)    : plumbing;;
-               for-each-ref)     : plumbing;;
-               hash-object)      : plumbing;;
-               http-*)           : transport;;
-               index-pack)       : plumbing;;
-               init-db)          : deprecated;;
-               local-fetch)      : plumbing;;
-               ls-files)         : plumbing;;
-               ls-remote)        : plumbing;;
-               ls-tree)          : plumbing;;
-               mailinfo)         : plumbing;;
-               mailsplit)        : plumbing;;
-               merge-*)          : plumbing;;
-               mktree)           : plumbing;;
-               mktag)            : plumbing;;
-               pack-objects)     : plumbing;;
-               pack-redundant)   : plumbing;;
-               pack-refs)        : plumbing;;
-               parse-remote)     : plumbing;;
-               patch-id)         : plumbing;;
-               prune)            : plumbing;;
-               prune-packed)     : plumbing;;
-               quiltimport)      : import;;
-               read-tree)        : plumbing;;
-               receive-pack)     : plumbing;;
-               remote-*)         : transport;;
-               rerere)           : plumbing;;
-               rev-list)         : plumbing;;
-               rev-parse)        : plumbing;;
-               runstatus)        : plumbing;;
-               sh-setup)         : internal;;
-               shell)            : daemon;;
-               show-ref)         : plumbing;;
-               send-pack)        : plumbing;;
-               show-index)       : plumbing;;
-               ssh-*)            : transport;;
-               stripspace)       : plumbing;;
-               symbolic-ref)     : plumbing;;
-               unpack-file)      : plumbing;;
-               unpack-objects)   : plumbing;;
-               update-index)     : plumbing;;
-               update-ref)       : plumbing;;
-               update-server-info) : daemon;;
-               upload-archive)   : plumbing;;
-               upload-pack)      : plumbing;;
-               write-tree)       : plumbing;;
-               var)              : infrequent;;
-               verify-pack)      : infrequent;;
-               verify-tag)       : plumbing;;
-               *) echo $i;;
-               esac
-       done
+       __git_list_commands porcelain
 }
 
 __git_porcelain_commands=
@@ -1575,6 +1512,13 @@ _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
@@ -1584,11 +1528,9 @@ _git_help ()
                ;;
        esac
        __git_compute_all_commands
-       __gitcomp "$__git_all_commands $(__git_aliases)
-               attributes cli core-tutorial cvs-migration
-               diffcore everyday gitk glossary hooks ignore modules
-               namespaces repository-layout revisions tutorial tutorial-2
-               workflows
+       __git_compute_all_guides
+       __gitcomp "$__git_all_commands $(__git_aliases) $__git_all_guides
+               gitk
                "
 }
 
@@ -3049,7 +2991,7 @@ __git_complete_common () {
 __git_cmds_with_parseopt_helper=
 __git_support_parseopt_helper () {
        test -n "$__git_cmds_with_parseopt_helper" ||
-               __git_cmds_with_parseopt_helper="$(__git --list-parseopt-builtins)"
+               __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
 
        case " $__git_cmds_with_parseopt_helper " in
        *" $1 "*)