How to fix apt bash completion in Ubuntu/debian

In some situations, especially when using an openvz vps one may notice that auto-completion is not working as it should (especially on debian). Luckily the fix is simple, in your terminal type:

apt-get install bash-completion

 

If that doesn’t work you can try the following

sudo apt-get install --reinstall bash-completion

or

sudo apt-get install auto-complete-el

or at a last result edit the following

sudo nano /etc/bash.bashrc

and change

# enable bash completion in interactive shells
# if ! shopt -oq posix; then
# if [ -f /usr/share/bash-completion/bash_completion ]; then
# . /usr/share/bash-completion/bash_completion
# elif [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
# fi
# fi

to

# enable bash completion in interactive shells
if ! shopt -oq posix; then
 if [ -f /usr/share/bash-completion/bash_completion ]; then
 . /usr/share/bash-completion/bash_completion
 elif [ -f /etc/bash_completion ]; then
 . /etc/bash_completion
 fi
fi

You may also like...

1 Response

  1. Ruben Alves says:

    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.

Leave a Reply