On Mon, Sep 19, 2022 at 09:20:14AM +0800, t.feng via Grub-devel wrote: > SC2207 (warning): Prefer mapfile or read -a to split > command output (or quote to avoid splitting). > SC2120 (warning): __grub_get_options_from_help references arguments, > but none are ever passed. > SC2155 (warning): Declare and assign separately to avoid > masking return values. > > In grub-completion.bash.in line 56: > COMPREPLY=($(compgen -P "${2-}" -W "${1-}" -S "${4-}" -- > "$cur")) > ^-- SC2207 (warning) > > In grub-completion.bash.in line 63: > __grub_get_options_from_help () { > ^-- SC2120 (warning) > > In grub-completion.bash.in line 115: > local config_file=$(__grub_dir)/grub.cfg > ^---------^ SC2155 (warning) > > In grub-completion.bash.in line 119: > COMPREPLY=( $(compgen \ > ^-- SC2207 (warning) > > In grub-completion.bash.in line 126: > local grub_dir=$(__grub_dir) > ^------^ SC2155 (warning) > > In grub-completion.bash.in line 128: > COMPREPLY=( $( compgen -f -X '!*/*.mod' -- "${grub_dir}/$cur" | { > ^-- SC2207 (warning) > > SC2120: the current code meets the exception and does not need to be > modified > > ref:https://github.com/koalaman/shellcheck/wiki/SC2207 > ref:https://github.com/koalaman/shellcheck/wiki/SC2120 > ref:https://github.com/koalaman/shellcheck/wiki/SC2155
I think this should be split into three patches. And again missing SOB... > --- > .../bash-completion.d/grub-completion.bash.in | 40 ++++++++++++------- > 1 file changed, 25 insertions(+), 15 deletions(-) > > diff --git a/util/bash-completion.d/grub-completion.bash.in > b/util/bash-completion.d/grub-completion.bash.in > index 93d143480..7449e629a 100644 > --- a/util/bash-completion.d/grub-completion.bash.in > +++ b/util/bash-completion.d/grub-completion.bash.in > @@ -53,7 +53,10 @@ __grubcomp () { > ;; > *) > local IFS=' '$'\t'$'\n' > - COMPREPLY=($(compgen -P "${2-}" -W "${1-}" -S "${4-}" -- "$cur")) > + COMPREPLY=() > + while read -r line; do > + COMPREPLY+=("${line}") > + done < <(compgen -P "${2-}" -W "${1-}" -S "${4-}" -- "$cur") > ;; > esac > } > @@ -112,28 +115,35 @@ __grub_get_last_option () { > > __grub_list_menuentries () { > local cur="${COMP_WORDS[COMP_CWORD]}" > - local config_file=$(__grub_dir)/grub.cfg > + local config_file > + config_file=$(__grub_dir)/grub.cfg > > if [ -f "$config_file" ];then > local IFS=$'\n' > - COMPREPLY=( $(compgen \ > - -W "$( awk -F "[\"']" '/menuentry/ { print $2 }' $config_file )" > \ > - -- "$cur" )) #'# Help emacs syntax highlighting > + COMPREPLY=() > + while read -r line; do This looks strange. The shellcheck suggest "read -a" and you use "read -r" here. Could you explain that? > + COMPREPLY+=("${line}") > + done < <(compgen \ > + -W "$( awk -F "[\"']" '/menuentry/ { print $2 }' > $config_file )" \ > + -- "$cur" ) #'# Help emacs syntax highlighting > fi > } > > __grub_list_modules () { > - local grub_dir=$(__grub_dir) > + local grub_dir > + grub_dir=$(__grub_dir) > local IFS=$'\n' > - COMPREPLY=( $( compgen -f -X '!*/*.mod' -- "${grub_dir}/$cur" | { > - while read -r tmp; do > - [ -n "$tmp" ] && { > - tmp=${tmp##*/} > - printf '%s\n' ${tmp%.mod} > - } > - done > - } > - )) > + COMPREPLY=() > + while read -r line; do > + COMPREPLY+=("${line}") > + done < <(compgen -f -X '!*/*.mod' -- "${grub_dir}/$cur" | { > + while read -r tmp; do > + [ -n "$tmp "] && { It seems to me last '"' is in wrong place. > + tmp=${tmp##*/} > + printf '%s\n' ${tmp%.mod} > + } > + done > + }) > } Daniel _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel