Bug#961660: Cause is have() Wrapper Function of Function _have()

2021-08-25 Thread Gabriel F. T. Gomes
Thanks for the update.

I'll close the bug report now. Feel free to reopen it if anything else pops-up.



Bug#961660: Cause is have() Wrapper Function of Function _have()

2021-08-24 Thread Jürgen Kuri
Hello Gabriel,

> If I try to complete the second word, then it doesn't work, but that's
> because I don't have the configuration file under /etc and I believe
> that this is unrelated to your problem:

>  $ fsmtool2 showconfig 
>  grep: /etc/fsmd2/fsmd2.conf: No such file or directory
Yes, that's unrelated.


> So, would you be willing to make that change in your scripts? It looks
> like the right thing to do anyway.
I did this already:

1) I removed my old workaround, storing the completion script
   below /etc/bash_completion.d/,

   a) not using anymore the .install files as a workaround

   b) using dh_bash-completion which stores it below
  /usr/share/bash-completion/completions/ which is the
  right way - yes (there is only one completion script
  left from distribution side, "git-prompt")

   c) I removed the broken surrounding "have(){ }" function not
  using it anymore as many other do (look into some completion
  scripts, neither have() nor _have() is used)


It works now for Stretch, Buster and Bullseye. By the way, have() is also 
broken in Bullseye, with _have() it works.

-- 
Thanks
Jürgen



Bug#961660: Cause is have() Wrapper Function of Function _have()

2021-08-23 Thread Gabriel F. T. Gomes
On Mon, 23 Aug 2021 19:36:34 -0300
"Gabriel F. T. Gomes"  wrote:
>
> I will create a chroot with old-stable (buster) to check if older
> versions of bash-completion have this problem.

Indeed, now I was able to reproduce it.

And yes, using _have instead of have does fix the problem.

So, would you be willing to make that change in your scripts? It looks
like the right thing to do anyway.


Cheers,
Gabriel



Bug#961660: Cause is have() Wrapper Function of Function _have()

2021-08-23 Thread Gabriel F. T. Gomes
Hello Jürgen,

thanks for following up on this bug.

On Mon, 23 Aug 2021 13:11:28 +0200
Jürgen Kuri  wrote:
>
> If have() is used AND bash-completion script is stored into directory
> 
>   /usr/share/bash-completion/completions

I'm still trying to reproduce the problem, so...

I copied the file that you attached to message #15 [1,2] into
/usr/share/bash-completion/completions/fsmtool2, as can be verified in
the following snippet:

  $ head /usr/share/bash-completion/completions/fsmtool2
  have fsmtool2 && {
  _fsmtool2_commands() {
COMPREPLY=( $(compgen -W "help showconfig showfiles showfileslex deleteall" 
-- $1) )
  }
  
  _fsmtool2()
  {
local areas command cur
cur=${COMP_WORDS[COMP_CWORD]}
command=${COMP_WORDS[1]}

Then, I tried basic completion:

  $ fsmtool2 
  deleteall help  showconfigshowfiles showfileslex  

i.e.: it completes with the basic commands correctly.

If I try to complete the second word, then it doesn't work, but that's
because I don't have the configuration file under /etc and I believe
that this is unrelated to your problem:

  $ fsmtool2 showconfig 
  grep: /etc/fsmd2/fsmd2.conf: No such file or directory

> completion does not work anymore.

Perhaps this only works for me because I'm running sid and testing?
But it does work for me.

I will create a chroot with old-stable (buster) to check if older
versions of bash-completion have this problem.

> If we replace have() by _have() or simply remove it in the bash completion 
> script (like many other do) it will work in both storage paths.

Can you do that?
I mean, does it fix the problems you are hitting?

While I understand that installing things under /etc/bash_completion.d/
made things work for you, we can't change dh_bash-completion to install
things under that directory. dh_bash-completion must install to
/usr/share/bash-completion/completions.


Cheers,
Gabriel


[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=961660#15
[2] 
https://bugs.debian.org/cgi-bin/bugreport.cgi?att=1;bug=961660;filename=fsmtool2-completion;msg=15



Bug#961660: Cause is have() Wrapper Function of Function _have()

2021-08-23 Thread Jürgen Kuri
Hello Gabriel,

I found the cause. It is the wrapper function have() of the obviously newer 
function _have() in the shell script

/usr/share/bash-completion/bash_completion

As shown there, have() is still kept for backwards compatibility reasons:

--8<-
# This function checks whether we have a given program on the system.
#
_have()
{
# Completions for system administrator commands are installed as well in
# case completion is attempted via `sudo command ...'.
PATH=$PATH:/usr/sbin:/sbin:/usr/local/sbin type $1 &>/dev/null
}

# Backwards compatibility for compat completions that use have().
# @deprecated should no longer be used; generally not needed with dynamically
# loaded completions, and _have is suitable for runtime use.
have()
{
unset -v have
_have $1 && have=yes
}
--8<-

If have() is used AND bash-completion script is stored into directory

/usr/share/bash-completion/completions

completion does not work anymore. If the script with the old have() function is 
stored in the path

/etc/bash_completion.d/

it will work as reported earlier.

If we replace have() by _have() or simply remove it in the bash completion 
script (like many other do) it will work in both storage paths.


-- 
Jürgen