scop / bash-completion

Programmable completion functions for bash
GNU General Public License v2.0
2.92k stars 380 forks source link

apt-get not completing package names on Ubuntu 22.04 #807

Open leoarnold opened 2 years ago

leoarnold commented 2 years ago

Hi there,

just installed Kubuntu 22.04.1 Desktop and noticed that

$ sudo apt-get insta<TAB>

would autocomplete, but

$ sudo apt-get install thunderb<TAB>

would not.

Reporting it here as a reference. May already be fixed in current development state.

Describe the feature/solution

I looked into the code of the version packaged with Ubuntu 18.04 and found the line

COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \

So I ran

$ apt-cache --no-generate pkgnames thunderb
E: The package cache file is corrupted, it has the wrong hash

which was weird because sudo apt-get update passed without error.

The solution was to purge the cache and refresh:

$ sudo rm -rf /var/lib/apt/lists/*
$ sudo apt-get update

and tab completion worked again.

Would be nice if that error message was not silently swallowed by the completion though.

Maintenance (please complete the following information)

scop commented 2 years ago

Suppressing error output from underlying invoked commands is a "cheap" general practice we tend to follow, because letting it through may cause an interleaved error/completion mess, the errors may make no sense to users, and/or presence of various commands or support for args we invoke them with might not be essential for the completion to work (graceful degradation).

I'm not against improving on this practice, but we should establish a way to do it so it's clear what and where is suppressed intentionally, and what's just an oversight. Maybe this means just some documentation and comments on the matter. Maybe it would be useful to make suppression optional, e.g. skip it in a "debug mode". Anyway it will require careful examination of each case separately.

For example, related to this particular case: for better or for worse, we still support the version of apt-cache that is present on Ubuntu 14.04. It doesn't understand the --no-generate option, so if we just let the error output through, it'll be mostly just an annoyance to users. Such a version of apt-cache isn't probably that relevant these days as far as new releases of bash-completion go, and our support for it is mostly a side effect of us running tests on Ubuntu 14.04 to cover oldish bash versions, but to illustrate.