Hi Gabriel, On Mon, 2021-03-15 at 09:52 -0300, Gabriel F. T. Gomes wrote: > On Sat, 13 Mar 2021, Kevin Locke wrote: >> I've attached a patch to fix the issue by requiring complete to follow a >> line break or semicolon. It obviously does not address the root of the >> problem of reliably differentiating a list of paths from a Bash script. >> (Which is not really possible, since a list of paths is a valid bash >> script.) But it may be a sufficient quick fix until/unless #785271 is >> addressed. > > I'm not sure we will ever be able to correctly detect everything... > Anyhow, your patch looks not only sufficient, but correct on its own. > I'll check if it works correctly with the scripts currently installed > under my /usr/share/bash-completion. > > Also, the detection algorithm has been kindly written by sergiodj (CC), > so I'll give him some time to weigh in, then I'll apply your fix.
Thanks for reviewing the patch! While looking at it again this morning, I noticed a potential issue: The patched version wouldn't match the last line of _have mycommand && _mycommand() { ... } && complete ... Which appears to be a common idiom for only defining the function and completion if the command is in $PATH. I've attached an updated version which matches & and | in addition to ; as command separators. We may also want to consider modifying the compgen expression in the same way. Thanks again, Kevin
>From 1b21115318d9620ac7770f1051a536c8a8f3139f Mon Sep 17 00:00:00 2001 Message-Id: <1b21115318d9620ac7770f1051a536c8a8f3139f.1615813233.git.ke...@kevinlocke.name> From: Kevin Locke <ke...@kevinlocke.name> Date: Sat, 13 Mar 2021 10:18:37 -0700 Subject: [PATCH v2] dh_bash-completion: Tighten is_filelist matching The regular expressions in is_filelist which matches "well-known idioms on bash scripts" currently matches the path to the bash-completion script in the nitrokey-app package: 'data/bash-autocomplete/nitrokey-app' =~ /\s*complete.*-[A-Za-z].*/ Avoid this by ensuring the is only matched when following a line break or character which can be used to chain shell commands. Signed-off-by: Kevin Locke <ke...@kevinlocke.name> --- debian/extra/debhelper/dh_bash-completion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Changes in v2: * Match & and | in addition to ; as command separators. This is important for `... && complete`, which is a common idiom. diff --git a/debian/extra/debhelper/dh_bash-completion b/debian/extra/debhelper/dh_bash-completion index d1d9bf2e..7999151c 100755 --- a/debian/extra/debhelper/dh_bash-completion +++ b/debian/extra/debhelper/dh_bash-completion @@ -75,7 +75,7 @@ sub is_filelist { # # - If we see an "if...then" construction in the file. We # take into account multi-line statements. - if (/\s*complete.*-[A-Za-z].*/ + if (/(^|[|&;])\s*complete.*-[A-Za-z].*/ || /\$\(.*\)/ || /\s*compgen.*-[A-Za-z].*/ || /\s*if.*;.*then/s) { -- 2.30.2