Skip to content

Commit dd33472

Browse files
szedergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e1e0008 commit dd33472

File tree

2 files changed

+48
-24
lines changed

2 files changed

+48
-24
lines changed

contrib/completion/git-completion.bash

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,96 +2229,112 @@ __git_compute_config_vars ()
22292229
}
22302230

22312231
# 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.
22322239
__git_complete_config_variable_value ()
22332240
{
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
22352251

22362252
if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
2237-
varname="${prev,,}"
2253+
varname="${varname,,}"
22382254
else
2239-
varname="$(echo "$prev" |tr A-Z a-z)"
2255+
varname="$(echo "$varname" |tr A-Z a-z)"
22402256
fi
22412257

22422258
case "$varname" in
22432259
branch.*.remote|branch.*.pushremote)
2244-
__gitcomp_nl "$(__git_remotes)"
2260+
__gitcomp_nl "$(__git_remotes)" "" "$cur_"
22452261
return
22462262
;;
22472263
branch.*.merge)
2248-
__git_complete_refs
2264+
__git_complete_refs --cur="$cur_"
22492265
return
22502266
;;
22512267
branch.*.rebase)
2252-
__gitcomp "false true merges preserve interactive"
2268+
__gitcomp "false true merges preserve interactive" "" "$cur_"
22532269
return
22542270
;;
22552271
remote.pushdefault)
2256-
__gitcomp_nl "$(__git_remotes)"
2272+
__gitcomp_nl "$(__git_remotes)" "" "$cur_"
22572273
return
22582274
;;
22592275
remote.*.fetch)
2260-
local remote="${prev#remote.}"
2276+
local remote="${varname#remote.}"
22612277
remote="${remote%.fetch}"
2262-
if [ -z "$cur" ]; then
2278+
if [ -z "$cur_" ]; then
22632279
__gitcomp_nl "refs/heads/" "" "" ""
22642280
return
22652281
fi
2266-
__gitcomp_nl "$(__git_refs_remotes "$remote")"
2282+
__gitcomp_nl "$(__git_refs_remotes "$remote")" "" "$cur_"
22672283
return
22682284
;;
22692285
remote.*.push)
2270-
local remote="${prev#remote.}"
2286+
local remote="${varname#remote.}"
22712287
remote="${remote%.push}"
22722288
__gitcomp_nl "$(__git for-each-ref \
2273-
--format='%(refname):%(refname)' refs/heads)"
2289+
--format='%(refname):%(refname)' refs/heads)" "" "$cur_"
22742290
return
22752291
;;
22762292
pull.twohead|pull.octopus)
22772293
__git_compute_merge_strategies
2278-
__gitcomp "$__git_merge_strategies"
2294+
__gitcomp "$__git_merge_strategies" "" "$cur_"
22792295
return
22802296
;;
22812297
color.pager)
2282-
__gitcomp "false true"
2298+
__gitcomp "false true" "" "$cur_"
22832299
return
22842300
;;
22852301
color.*.*)
22862302
__gitcomp "
22872303
normal black red green yellow blue magenta cyan white
22882304
bold dim ul blink reverse
2289-
"
2305+
" "" "$cur_"
22902306
return
22912307
;;
22922308
color.*)
2293-
__gitcomp "false true always never auto"
2309+
__gitcomp "false true always never auto" "" "$cur_"
22942310
return
22952311
;;
22962312
diff.submodule)
2297-
__gitcomp "$__git_diff_submodule_formats"
2313+
__gitcomp "$__git_diff_submodule_formats" "" "$cur_"
22982314
return
22992315
;;
23002316
help.format)
2301-
__gitcomp "man info web html"
2317+
__gitcomp "man info web html" "" "$cur_"
23022318
return
23032319
;;
23042320
log.date)
2305-
__gitcomp "$__git_log_date_formats"
2321+
__gitcomp "$__git_log_date_formats" "" "$cur_"
23062322
return
23072323
;;
23082324
sendemail.aliasfiletype)
2309-
__gitcomp "mutt mailrc pine elm gnus"
2325+
__gitcomp "mutt mailrc pine elm gnus" "" "$cur_"
23102326
return
23112327
;;
23122328
sendemail.confirm)
2313-
__gitcomp "$__git_send_email_confirm_options"
2329+
__gitcomp "$__git_send_email_confirm_options" "" "$cur_"
23142330
return
23152331
;;
23162332
sendemail.suppresscc)
2317-
__gitcomp "$__git_send_email_suppresscc_options"
2333+
__gitcomp "$__git_send_email_suppresscc_options" "" "$cur_"
23182334
return
23192335
;;
23202336
sendemail.transferencoding)
2321-
__gitcomp "7bit 8bit quoted-printable base64"
2337+
__gitcomp "7bit 8bit quoted-printable base64" "" "$cur_"
23222338
return
23232339
;;
23242340
*.*)
@@ -2430,7 +2446,8 @@ __git_complete_config_variable_name_and_value ()
24302446
{
24312447
case "$cur" in
24322448
*=*)
2433-
# in the next patch...
2449+
__git_complete_config_variable_value \
2450+
--varname="${cur%%=*}" --cur="${cur#*=}"
24342451
;;
24352452
*)
24362453
__git_complete_config_variable_name --sfx='='

t/t9902-completion.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,13 @@ test_expect_success 'git -c - variable name' '
17331733
EOF
17341734
'
17351735

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+
17361743
test_expect_success 'sourcing the completion script clears cached commands' '
17371744
__git_compute_all_commands &&
17381745
verbose test -n "$__git_all_commands" &&

0 commit comments

Comments
 (0)