completion: complete values of configuration variables after 'git -c var='
'git config' expects a configuration variable's name and value in separate options, so we complete values as they stand on their own on the command line. 'git -c', however, expects them in a single option joined by a '=' character, so we should be able to complete values when they are following 'section.name=' in the same word. Add new options to the __git_complete_config_variable_value() function to allow callers to specify the current word to be completed and the configuration variable whose value is to be completed, and use these to complete possible values after 'git -c 'section.name=<TAB>'. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
SZEDER Gábor committed
Aug 13, 2019 at 14:26 UTC
dd33472831756895a86153c651c18580a6dccbc8
2 files changed
+48
-24
contrib/completion/git-completion.bash
+41
-24
@@ -2229,96 +2229,112 @@ __git_compute_config_vars ()
2229
}
2230
2231
# Completes possible values of various configuration variables.
2232
+#
2233
+# Usage: __git_complete_config_variable_value [<option>]...
2234
+# --varname=<word>: The name of the configuration variable whose value is
2235
+# to be completed. Defaults to the previous word on the
2236
+# command line.
2237
+# --cur=<word>: The current value to be completed. Defaults to the current
2238
+# word to be completed.
2239
__git_complete_config_variable_value ()
2240
{
2234
- local varname
2241
+ local varname="$prev" cur_="$cur"
2242
+
2243
+ while test $# != 0; do
2244
+ case "$1" in
2245
+ --varname=*) varname="${1##--varname=}" ;;
2246
+ --cur=*) cur_="${1##--cur=}" ;;
2247
+ *) return 1 ;;
2248
+ esac
2249
+ shift
2250
+ done
2251
2252
if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
2237
- varname="${prev,,}"
2253
+ varname="${varname,,}"
2254
else
2239
- varname="$(echo "$prev" |tr A-Z a-z)"
2255
+ varname="$(echo "$varname" |tr A-Z a-z)"
2256
fi
2257
2258
case "$varname" in
2259
branch.*.remote|branch.*.pushremote)
2244
- __gitcomp_nl "$(__git_remotes)"
2260
+ __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2261
return
2262
;;
2263
branch.*.merge)
2248
- __git_complete_refs
2264
+ __git_complete_refs --cur="$cur_"
2265
return
2266
;;
2267
branch.*.rebase)
2252
- __gitcomp "false true merges preserve interactive"
2268
+ __gitcomp "false true merges preserve interactive" "" "$cur_"
2269
return
2270
;;
2271
remote.pushdefault)
2256
- __gitcomp_nl "$(__git_remotes)"
2272
+ __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2273
return
2274
;;
2275
remote.*.fetch)
2260
- local remote="${prev#remote.}"
2276
+ local remote="${varname#remote.}"
2277
remote="${remote%.fetch}"
2262
- if [ -z "$cur" ]; then
2278
+ if [ -z "$cur_" ]; then
2279
__gitcomp_nl "refs/heads/" "" "" ""
2280
return
2281
fi
2266
- __gitcomp_nl "$(__git_refs_remotes "$remote")"
2282
+ __gitcomp_nl "$(__git_refs_remotes "$remote")" "" "$cur_"
2283
return
2284
;;
2285
remote.*.push)
2270
- local remote="${prev#remote.}"
2286
+ local remote="${varname#remote.}"
2287
remote="${remote%.push}"
2288
__gitcomp_nl "$(__git for-each-ref \
2273
- --format='%(refname):%(refname)' refs/heads)"
2289
+ --format='%(refname):%(refname)' refs/heads)" "" "$cur_"
2290
return
2291
;;
2292
pull.twohead|pull.octopus)
2293
__git_compute_merge_strategies
2278
- __gitcomp "$__git_merge_strategies"
2294
+ __gitcomp "$__git_merge_strategies" "" "$cur_"
2295
return
2296
;;
2297
color.pager)
2282
- __gitcomp "false true"
2298
+ __gitcomp "false true" "" "$cur_"
2299
return
2300
;;
2301
color.*.*)
2302
__gitcomp "
2303
normal black red green yellow blue magenta cyan white
2304
bold dim ul blink reverse
2289
- "
2305
+ " "" "$cur_"
2306
return
2307
;;
2308
color.*)
2293
- __gitcomp "false true always never auto"
2309
+ __gitcomp "false true always never auto" "" "$cur_"
2310
return
2311
;;
2312
diff.submodule)
2297
- __gitcomp "$__git_diff_submodule_formats"
2313
+ __gitcomp "$__git_diff_submodule_formats" "" "$cur_"
2314
return
2315
;;
2316
help.format)
2301
- __gitcomp "man info web html"
2317
+ __gitcomp "man info web html" "" "$cur_"
2318
return
2319
;;
2320
log.date)
2305
- __gitcomp "$__git_log_date_formats"
2321
+ __gitcomp "$__git_log_date_formats" "" "$cur_"
2322
return
2323
;;
2324
sendemail.aliasfiletype)
2309
- __gitcomp "mutt mailrc pine elm gnus"
2325
+ __gitcomp "mutt mailrc pine elm gnus" "" "$cur_"
2326
return
2327
;;
2328
sendemail.confirm)
2313
- __gitcomp "$__git_send_email_confirm_options"
2329
+ __gitcomp "$__git_send_email_confirm_options" "" "$cur_"
2330
return
2331
;;
2332
sendemail.suppresscc)
2317
- __gitcomp "$__git_send_email_suppresscc_options"
2333
+ __gitcomp "$__git_send_email_suppresscc_options" "" "$cur_"
2334
return
2335
;;
2336
sendemail.transferencoding)
2321
- __gitcomp "7bit 8bit quoted-printable base64"
2337
+ __gitcomp "7bit 8bit quoted-printable base64" "" "$cur_"
2338
return
2339
;;
2340
*.*)
@@ -2430,7 +2446,8 @@ __git_complete_config_variable_name_and_value ()
2446
{
2447
case "$cur" in
2448
*=*)
2433
- # in the next patch...
2449
+ __git_complete_config_variable_value \
2450
+ --varname="${cur%%=*}" --cur="${cur#*=}"
2451
;;
2452
*)
2453
__git_complete_config_variable_name --sfx='='
t/t9902-completion.sh
+7
@@ -1733,6 +1733,13 @@ test_expect_success 'git -c - variable name' '
1733
EOF
1734
'
1735
1736
+test_expect_success 'git -c - value' '
1737
+ test_completion "git -c color.pager=" <<-\EOF
1738
+ false Z
1739
+ true Z
1740
+ EOF
1741
+'
1742
+
1743
test_expect_success 'sourcing the completion script clears cached commands' '
1744
__git_compute_all_commands &&
1745
verbose test -n "$__git_all_commands" &&