completion: use awk for filtering the config entries

Commits 1e0ee4087e (completion: add and use __git_compute_first_level_config_vars_for_section, 2024-02-10) and 6e32f718ff (completion: add and use __git_compute_second_level_config_vars_for_section, 2024-02-10) introduced new helpers for config completion. Both helpers use a pipeline of grep and awk to filter the list of config entries. awk is perfectly capable of filtering, so let's eliminate the grep process and move the filtering into the awk script. The "-E" grep option (extended syntax) was not necessary, as $section is a single word. While at it, wrap the over-long lines to make them more readable. Signed-off-by: Beat Bolli <dev+git@drbeat.li> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Beat Bolli committed Feb 16, 2024 at 18:10 UTC 3c2e3d42d117197ead05264d47fb6eea0a3834c3
1 file changed +4 -2
contrib/completion/git-completion.bash
+4 -2
@@ -2673,7 +2673,8 @@ __git_compute_first_level_config_vars_for_section ()
2673 __git_compute_config_vars
2674 local this_section="__git_first_level_config_vars_for_section_${section}"
2675 test -n "${!this_section}" ||
2676 - printf -v "__git_first_level_config_vars_for_section_${section}" %s "$(echo "$__git_config_vars" | grep -E "^${section}\.[a-z]" | awk -F. '{print $2}')"
2676 + printf -v "__git_first_level_config_vars_for_section_${section}" %s \
2677 + "$(echo "$__git_config_vars" | awk -F. "/^${section}\.[a-z]/ { print \$2 }")"
2678 }
2679
2680 __git_compute_second_level_config_vars_for_section ()
@@ -2682,7 +2683,8 @@ __git_compute_second_level_config_vars_for_section ()
2683 __git_compute_config_vars_all
2684 local this_section="__git_second_level_config_vars_for_section_${section}"
2685 test -n "${!this_section}" ||
2685 - printf -v "__git_second_level_config_vars_for_section_${section}" %s "$(echo "$__git_config_vars_all" | grep -E "^${section}\.<" | awk -F. '{print $3}')"
2686 + printf -v "__git_second_level_config_vars_for_section_${section}" %s \
2687 + "$(echo "$__git_config_vars_all" | awk -F. "/^${section}\.</ { print \$3 }")"
2688 }
2689
2690 __git_config_sections=