From 5cf2cefa94c24decef34bfa90baa05710920d6fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6ppner?= Date: Wed, 11 Mar 2026 18:43:47 +0100 Subject: [PATCH] libutil/util_autocomp: Fix ShellCheck findings and apply coding style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apply coding style changes by reducing line breaks for a more compactly generated script and add double quotes to fix ShellCheck findings. Furthermore, remove the unused variable previous_word and use mapfile to read the output of compgen into the COMPREPLY array to avoid unwanted splitting and glob expansion. Reviewed-by: Szabina Korbai Signed-off-by: Jan Höppner --- libutil/util_autocomp_host.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/libutil/util_autocomp_host.c b/libutil/util_autocomp_host.c index 3d6bcb39..5b617cdd 100644 --- a/libutil/util_autocomp_host.c +++ b/libutil/util_autocomp_host.c @@ -22,18 +22,17 @@ #include "lib/util_autocomp.h" #include "lib/util_opt.h" -static const char *bash_script_part1 = "() {\n\n\ -\tlocal current_word previous_word options_array\n\n\ +static const char *bash_script_part1 = "() {\n\ +\tlocal current_word options_array\n\ \tCOMPREPLY=()\n\n\ -\tcurrent_word=\"${COMP_WORDS[COMP_CWORD]}\"\n\n\ -\tprevious_word=\"${COMP_WORDS[COMP_CWORD-1]}\"\n\n\ +\tcurrent_word=\"${COMP_WORDS[COMP_CWORD]}\"\n\ \toptions_array=\""; -static const char *bash_script_part2 = "\tif [[ ${current_word} == -* || ${COMP_CWORD} -eq 1 ]] ; then\n\n\ -\t\tCOMPREPLY=( $(compgen -W \"${options_array}\" -- ${current_word} ) )\n\n\ -\t\treturn 0\n\n\ -\tfi\n\n\ -}\n\n\ +static const char *bash_script_part2 = "\tif [[ ${current_word} == -* || ${COMP_CWORD} -eq 1 ]] ; then\n\ +\t\tmapfile -t \"COMPREPLY\" < <(compgen -W \"${options_array}\" -- \"$current_word\")\n\ +\t\treturn 0\n\ +\tfi\n\ +}\n\ complete -F "; static char *format_name(const char *fmt, char *tool_name)