Bash-Completion Does not work for Apt

2

I am running a minimal Debian installation that comes with practically nothing installed. I am trying to get bash auto-complete working. I have looked over all the questions on this subject in superuser and askubuntu sites and this is what I have found.

I understand that I need to install bash-completion. I installed that on my system. I found I have to have this in my $HOME/.bashrc file:

if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi

That was already there. I read somewhere that it should be added to the /etc/profile file. I did that. I logged out and logged back in and it does not work. I added && echo "OK" to the files and when I load the terminal it says OK so I know its running it.

Auto-complete for programs and paths works, but that always worked even before I installed bash-completion. The main thing that doesn't work that is bothering me is apt. If I say sudo apt install ged and then hit tab twice it will not give a list of packages that start with that string like it does in Ubuntu and other OSs.

So basically, how can I get bash-completion to work with apt? Thank you in advance!

NULL

Posted 2016-07-23T17:15:50.280

Reputation: 121

Answers

2

What I had not noticed is that bash-completion has a folder in /usr/share/bash-completion/ called completion with separate files for each program that it supports.

I copied the apt file from my Ubuntu box and put it in that folder on my minimal Debian box. Now it works perfectly.

NULL

Posted 2016-07-23T17:15:50.280

Reputation: 121

1

How I solved it

I had auto completion problems trying to autocomplete wget with apt-get install wg[TAB][TAB] and I managed to solve it by removing the --no-generate parameter from the flies below:

/usr/share/bash-completion/completions/apt-cache
/usr/share/bash-completion/completions/apt-get

It is worth mentioning that these files are available only after you install bash-completion.

The --no-generate parameter I'm referring to can be seen in the line below, but I removed ALL --no-generate, not only from this line: https://github.com/scop/bash-completion/blob/master/completions/apt-get#L28

How did I come to this point?

I got to this point after running set -v previous to apt-get install wg[TAB][TAB], which showed that the command executed was:

apt-cache --no-generate pkgnames wg

and the output was an error:

E: Could not open file  - open (2: No such file or directory)

When I executed apt-cache pkgnames wg without the --no-generate I correctly got the list for autocompletion:

root@484f5c8f56ba:/# apt-cache pkgnames wg
wgalician-minimos
wget2
wgaelic
wget
wgerman-medical
wget2-dev

Hope this helps.

Ruben Alves

Posted 2016-07-23T17:15:50.280

Reputation: 11

Sounds worthy of an upstream bug report, if you haven't already! – Toby Speight – 2019-10-09T18:35:14.813

Are you able to reproduce on a fresh install? If no, don't report upstream! – dirdi – 2019-10-09T18:48:25.867

Yes, to reproduce I just try to autocomplete in ubuntu:18.04 or ubuntu:16.04 docker container. It fails all the times. – Ruben Alves – 2019-10-10T18:18:48.753