[Bug 1388445] Re: bash-completion, command-not-found and '_have' function

Peter Cordes peter at cordes.ca
Mon Dec 1 09:43:13 UTC 2014


It's done the way it is to save RAM and startup time for every
interactive bash.  If bash had to store both versions of a function, and
pick at runtime, it would be slightly slower every completion, and more
importantly, slightly slower to load.

 As I understand it, this is the design tradeoff that bash-completion
has decided to make.  It's already a huge amount of shell code running
every time an interactive shell starts, and I guess any bandaid that can
be put on the problem is applied...

 I don't think you want to suppress error messages.   Instead of having something just silently not working, it's better for the user to see something is wrong, so they can
 complete -r; . /usr/share/bash-completion/bash_completion
or start a new shell.  If they don't understand what happened or why, then they don't have to.  Or IDK, maybe it would be better to 2>/dev/null something, and have silently not-working completion for that until the restart their shell.


** Changed in: bash-completion (Ubuntu)
       Status: New => Opinion

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to bash-completion in Ubuntu.
https://bugs.launchpad.net/bugs/1388445

Title:
  bash-completion, command-not-found and '_have' function

Status in bash-completion package in Ubuntu:
  Opinion

Bug description:
  In short, how it looks for me as a user:

  I have dctrl-tools package installed. I open bash and type "sudo apt-get remove dctrl-tools".
  Then (for example, in the same bash) I type "sudo dpkg --purge cr<TAB>", and this is what I get:
  --begin quote--
  sasha at sasha-netbook:~/Downloads$ dpkg --purge crThe program 'grep-status' is currently not installed. You can install it by typing:
  sudo apt-get install dctrl-tools
  --end quote--

  ===================================================

  Why this happens:

  In many /usr/share/bash-completion/completions/* files we see the following construct:
  _have grep-status && {
  _comp_dpkg_purgeable_packages()
  {
      grep-status ...
  }
  } || {
  _comp_dpkg_purgeable_packages()
  {
      ...
  }
  }

  I.e. the existence of some command ("grep-status" in the above example) that is needed for some function ("_comp_dpkg_purgeable_packages" in the above example) is determined (using "_have" predefined func) not at the time of calling the function, but at the time of function declaration. On the one hand this is could give some performance benefits, but on another hand checked command can disappear after check:
  e.g. user opens several bash sessions, then removes some package and in all bash'es that were opened before removing the package completion can become broken.

  ===================================================

  What should be done:

  I don't know. One possible solution is to move _have-checks inside the
  body of defined function (as you understand, such stuff happens not
  only for _comp_dpkg_purgeable_packages / grep-status / dpkg --purge).
  Other is to, at least, somehow suppress command-not-found messages in
  bash-completion scripts.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/bash-completion/+bug/1388445/+subscriptions



More information about the foundations-bugs mailing list