]> git.ipfire.org Git - thirdparty/git.git/blobdiff - contrib/completion/git-completion.bash
completion: complete configuration sections and variable names for 'git -c'
[thirdparty/git.git] / contrib / completion / git-completion.bash
index e087c4bf0085add8e968e128db6b667acbc80320..367b1c50f450e055ab5572f6695ffd58c05ca0df 100644 (file)
@@ -340,7 +340,7 @@ __gitcomp ()
                        c="$c${4-}"
                        if [[ $c == "$cur_"* ]]; then
                                case $c in
-                               --*=*|*.) ;;
+                               --*=|*.) ;;
                                *) c="$c " ;;
                                esac
                                COMPREPLY[i++]="${2-}$c"
@@ -360,7 +360,7 @@ __gitcomp ()
                        c="$c${4-}"
                        if [[ $c == "$cur_"* ]]; then
                                case $c in
-                               --*=*|*.) ;;
+                               *=|*.) ;;
                                *) c="$c " ;;
                                esac
                                COMPREPLY[i++]="${2-}$c"
@@ -524,7 +524,7 @@ __git_index_files ()
                        # Even when a directory name itself does not contain
                        # any special characters, it will still be quoted if
                        # any of its (stripped) trailing path components do.
-                       # Because of this we may have seen the same direcory
+                       # Because of this we may have seen the same directory
                        # both quoted and unquoted.
                        if (p in paths)
                                # We have seen the same directory unquoted,
@@ -2225,10 +2225,11 @@ __git_config_vars=
 __git_compute_config_vars ()
 {
        test -n "$__git_config_vars" ||
-       __git_config_vars="$(git help --config-for-completion | sort | uniq)"
+       __git_config_vars="$(git help --config-for-completion | sort -u)"
 }
 
-_git_config ()
+# Completes possible values of various configuration variables.
+__git_complete_config_variable_value ()
 {
        local varname
 
@@ -2277,11 +2278,6 @@ _git_config ()
                __gitcomp "$__git_merge_strategies"
                return
                ;;
-       color.branch|color.diff|color.interactive|\
-       color.showbranch|color.status|color.ui)
-               __gitcomp "always never auto"
-               return
-               ;;
        color.pager)
                __gitcomp "false true"
                return
@@ -2293,6 +2289,10 @@ _git_config ()
                        "
                return
                ;;
+       color.*)
+               __gitcomp "false true always never auto"
+               return
+               ;;
        diff.submodule)
                __gitcomp "$__git_diff_submodule_formats"
                return
@@ -2321,28 +2321,40 @@ _git_config ()
                __gitcomp "7bit 8bit quoted-printable base64"
                return
                ;;
-       --get|--get-all|--unset|--unset-all)
-               __gitcomp_nl "$(__git_config_get_set_variables)"
-               return
-               ;;
        *.*)
                return
                ;;
        esac
+}
+
+# Completes configuration sections, subsections, variable names.
+#
+# Usage: __git_complete_config_variable_name [<option>]...
+# --sfx=<suffix>: A suffix to be appended to each fully completed
+#                 configuration variable name (but not to sections or
+#                 subsections) instead of the default space.
+__git_complete_config_variable_name ()
+{
+       local sfx
+
+       while test $# != 0; do
+               case "$1" in
+               --sfx=*)        sfx="${1##--sfx=}" ;;
+               *)              return 1 ;;
+               esac
+               shift
+       done
+
        case "$cur" in
-       --*)
-               __gitcomp_builtin config
-               return
-               ;;
        branch.*.*)
                local pfx="${cur%.*}." cur_="${cur##*.}"
-               __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_"
+               __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
                return
                ;;
        branch.*)
                local pfx="${cur%.*}." cur_="${cur#*.}"
                __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
-               __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_"
+               __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx"
                return
                ;;
        guitool.*.*)
@@ -2350,28 +2362,28 @@ _git_config ()
                __gitcomp "
                        argPrompt cmd confirm needsFile noConsole noRescan
                        prompt revPrompt revUnmerged title
-                       " "$pfx" "$cur_"
+                       " "$pfx" "$cur_" "$sfx"
                return
                ;;
        difftool.*.*)
                local pfx="${cur%.*}." cur_="${cur##*.}"
-               __gitcomp "cmd path" "$pfx" "$cur_"
+               __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
                return
                ;;
        man.*.*)
                local pfx="${cur%.*}." cur_="${cur##*.}"
-               __gitcomp "cmd path" "$pfx" "$cur_"
+               __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
                return
                ;;
        mergetool.*.*)
                local pfx="${cur%.*}." cur_="${cur##*.}"
-               __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
+               __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
                return
                ;;
        pager.*)
                local pfx="${cur%.*}." cur_="${cur#*.}"
                __git_compute_all_commands
-               __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
+               __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx"
                return
                ;;
        remote.*.*)
@@ -2379,27 +2391,72 @@ _git_config ()
                __gitcomp "
                        url proxy fetch push mirror skipDefaultUpdate
                        receivepack uploadpack tagOpt pushurl
-                       " "$pfx" "$cur_"
+                       " "$pfx" "$cur_" "$sfx"
                return
                ;;
        remote.*)
                local pfx="${cur%.*}." cur_="${cur#*.}"
                __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
-               __gitcomp_nl_append "pushDefault" "$pfx" "$cur_"
+               __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "$sfx"
                return
                ;;
        url.*.*)
                local pfx="${cur%.*}." cur_="${cur##*.}"
-               __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
+               __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
                return
                ;;
        *.*)
                __git_compute_config_vars
-               __gitcomp "$__git_config_vars"
+               __gitcomp "$__git_config_vars" "" "$cur" "$sfx"
                ;;
        *)
                __git_compute_config_vars
-               __gitcomp "$(echo "$__git_config_vars" | sed 's/\.[^ ]*/./g')"
+               __gitcomp "$(echo "$__git_config_vars" |
+                               awk -F . '{
+                                       sections[$1] = 1
+                               }
+                               END {
+                                       for (s in sections)
+                                               print s "."
+                               }
+                               ')"
+               ;;
+       esac
+}
+
+# Completes '='-separated configuration sections/variable names and values
+# for 'git -c section.name=value'.
+__git_complete_config_variable_name_and_value ()
+{
+       case "$cur" in
+       *=*)
+               # in the next patch...
+               ;;
+       *)
+               __git_complete_config_variable_name --sfx='='
+               ;;
+       esac
+}
+
+_git_config ()
+{
+       case "$prev" in
+       --get|--get-all|--unset|--unset-all)
+               __gitcomp_nl "$(__git_config_get_set_variables)"
+               return
+               ;;
+       *.*)
+               __git_complete_config_variable_value
+               return
+               ;;
+       esac
+       case "$cur" in
+       --*)
+               __gitcomp_builtin config
+               ;;
+       *)
+               __git_complete_config_variable_name
+               ;;
        esac
 }
 
@@ -2956,7 +3013,11 @@ __git_main ()
                        # Bash filename completion
                        return
                        ;;
-               -c|--namespace)
+               -c)
+                       __git_complete_config_variable_name_and_value
+                       return
+                       ;;
+               --namespace)
                        # we don't support completing these options' arguments
                        return
                        ;;