@matheusbsbs / matheus-bagliano / commits / 00652369ff
Fork 0

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>

Stephen Boyd committed May 8, 2009 at 18:23 UTC 00652369ff285f84e440f5d41d708283e30825d7
1 file changed +33
contrib/completion/git-completion.bash
+33
@@ -1322,6 +1322,35 @@ _git_send_email ()
1322 COMPREPLY=()
1323 }
1324
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 +
1354 _git_config ()
1355 {
1356 local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -1388,6 +1417,10 @@ _git_config ()
1417 __gitcomp "$__git_send_email_suppresscc_options"
1418 return
1419 ;;
1420 + --get|--get-all|--unset|--unset-all)
1421 + __gitcomp "$(__git_config_get_set_variables)"
1422 + return
1423 + ;;
1424 *.*)
1425 COMPREPLY=()
1426 return