-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shellcheck: Disable SC2207, as it messes with COMPREPLY #1791
Conversation
@cornfeedhobo @nwinkler @davidpfarrell can you give me a hand here? |
@NoahGorny no problem. It's a busy weekend but I'll do my best. Can you explain what you were doing to stumble on this so I can reproduce your thinking and/or issue? |
Alright. So what happens is that when we autocomplete something, lets say _bash-it-comp-enable-disable()
{
local enable_disable_args="alias completion plugin"
COMPREPLY=( $(compgen -W "${enable_disable_args}" -- ${cur}) )
} However, shellcheck is complaining about the way we read After some trials and errors by me, I ultimately gave up in the approach of making Lemme know what you think about it, but please feel no rush to answer! |
Using brainy theme to understand why we have this issue, we can see the output of compgen -W "${segments}" -- "${cur}" | cat -A Which output battery$
clock$
exitcode$
python$
ruby$
scm$
sudo$
todo$ So The solution is to use a while loop, like explained in SC2207 wiki. while IFS='' read -r line; do COMPREPLY+=("$line"); done < <(compgen -W "${segments}" -- "${cur}") I'll update #1790 to reflect that. |
@NoahGorny let me know if using a while loop is ok for completion reply. |
I guess that if this works- we should use it and not ignore the warning. |
Hi Team, Here's what I learned during my work on
I suspect we can use something like this:
NOTE: This is untested. If that doesn't work as-is, lemme know and I'll play around with it and figure out the syntax. |
@davidpfarrell mapfile is available for bash 4.x+ only. So using a while loop keep this compatibility with bash 3.2+ |
@NoahGorny Okay, I see what you mean. Here are my $0.02: shellcheck is worried about command output splitting:
In the example you provided you aren't splitting a command's output and we know the string, so I consider the current form preferable. Instead of making this disable global though, you should just put it above the command or at the top of the file. |
@NoahGorny Did you get a chance to read this? I'd much rather keep with the current form than change these lines to use read. |
+1 Compgen generate a list of matches from a word list, so if we have a clean word list, disabling this warning for the specific line is the best way. I will update #1790 with a disable. # shellcheck disable=SC2207
COMPREPLY=($(compgen -W "${actions}" -- "${cur}")) |
Disable SC2207
Motivation and Context
This shellcheck option is really messing our code, as we use COMPREPLY in many places
How Has This Been Tested?
Tested locally, saw that no such warnings were emitted the change
Types of changes
Checklist:
clean_files.txt
and formatted it usinglint_clean_files.sh
.