Skip to content

Commit 0065236

Browse files
bebarinogitster
authored andcommitted
bash completion: complete variable names for "git config" with options
This makes it easier for users to get and unset their configuration variables without having to open documentation or dig through their configuration file. __git_config_get_set_variables() retrieves the set configuration variables from the appropriate configuration file. For example, if the user has previously specified --global only the global variables are returned. The same applies for --system, and --file. If no location has been specified, all set variables are returned. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4bf1f68 commit 0065236

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

contrib/completion/git-completion.bash

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,35 @@ _git_send_email ()
13221322
COMPREPLY=()
13231323
}
13241324

1325+
__git_config_get_set_variables ()
1326+
{
1327+
local prevword word config_file= c=$COMP_CWORD
1328+
while [ $c -gt 1 ]; do
1329+
word="${COMP_WORDS[c]}"
1330+
case "$word" in
1331+
--global|--system|--file=*)
1332+
config_file="$word"
1333+
break
1334+
;;
1335+
-f|--file)
1336+
config_file="$word $prevword"
1337+
break
1338+
;;
1339+
esac
1340+
prevword=$word
1341+
c=$((--c))
1342+
done
1343+
1344+
for i in $(git --git-dir="$(__gitdir)" config $config_file --list \
1345+
2>/dev/null); do
1346+
case "$i" in
1347+
*.*)
1348+
echo "${i/=*/}"
1349+
;;
1350+
esac
1351+
done
1352+
}
1353+
13251354
_git_config ()
13261355
{
13271356
local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -1388,6 +1417,10 @@ _git_config ()
13881417
__gitcomp "$__git_send_email_suppresscc_options"
13891418
return
13901419
;;
1420+
--get|--get-all|--unset|--unset-all)
1421+
__gitcomp "$(__git_config_get_set_variables)"
1422+
return
1423+
;;
13911424
*.*)
13921425
COMPREPLY=()
13931426
return

0 commit comments

Comments
 (0)