Skip to content

Commit 3c2e3d4

Browse files
bbolligitster
authored andcommitted
completion: use awk for filtering the config entries
Commits 1e0ee40 (completion: add and use __git_compute_first_level_config_vars_for_section, 2024-02-10) and 6e32f71 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3e0d3cd commit 3c2e3d4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

contrib/completion/git-completion.bash

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,7 +2673,8 @@ __git_compute_first_level_config_vars_for_section ()
26732673
__git_compute_config_vars
26742674
local this_section="__git_first_level_config_vars_for_section_${section}"
26752675
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 }")"
26772678
}
26782679

26792680
__git_compute_second_level_config_vars_for_section ()
@@ -2682,7 +2683,8 @@ __git_compute_second_level_config_vars_for_section ()
26822683
__git_compute_config_vars_all
26832684
local this_section="__git_second_level_config_vars_for_section_${section}"
26842685
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 }")"
26862688
}
26872689

26882690
__git_config_sections=

0 commit comments

Comments
 (0)