I did some experiments and wrote a patch! Okay, so, I spend some more time thinking about this. And I think the bug is in apt's completion scripts. Because that *.bin files are simply cache. And lack of caches should not break program! This follows from my interpretation of FHS 3.0 5.5 ( https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch05s05.html ). And that *.bin files are located in /var/cache. And debian policy refers to FHS 3.0 ( https://www.debian.org/doc/debian-policy/ch-opersys.html#file-system-hierarchy ). So, the bug is in apt's completion scripts and we should simply remove "--no-generate" from them. And hence I attach a patch, which does exactly that.
This will cause completion scripts to regenerate caches as needed. This will work even if *.bin files are not present. And this will work even if we are in unprivileged bash, I tested this. Okay, so you can ask: what are speed implications of this? Well, I tested this on my main system (Intel Core i7) and I feel that even full cache regeneration takes zero time, i. e. it is absolutely instant. So I started qemu-system-x86_64 without -enable-kvm and tested there. Results are this: if caches are not present, then bash-completion is slow, it takes something like 10 seconds (in qemu in emulation mode!!!). But if caches are present, then bash-completion feels fast. So, it seems that apt is smart, it regenerates cache only if needed. So, there is no need to insert special "if" in completion scripts to check whether we should regenerate caches, apt already does this. Also, I found that file /usr/share/bash-completion/completions/apt is owned by apt, but file /usr/share/bash-completion/completions/apt-get is owned by bash-completion . So, I apply patch to "apt" only. Needed patch for "apt-get" is essentially the same. Also, I think "apt-get" (and similar) scripts should be transferred from "bash-completion" package to "apt". This patch is for current apt's "main", 9da15d149f97e0f26cf5b7e32405512a5e63523c . diff --git a/completions/bash/apt b/completions/bash/apt index 59a8eaa94..ff3d7bd24 100644 --- a/completions/bash/apt +++ b/completions/bash/apt @@ -173,6 +173,7 @@ _apt() fi # specific command arguments + # we don't pass "--no-generate" to "apt-cache" because we want completion to work even if caches are not present (#1034650) if [[ -v command ]]; then case $command in remove|purge|autoremove|autopurge) @@ -187,7 +188,7 @@ _apt() return 0 ;; show|list|download|changelog|depends|rdepends) - COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \ + COMPREPLY=( $( apt-cache pkgnames "$cur" \ 2> /dev/null ) ) return 0 ;; @@ -195,7 +196,7 @@ _apt() if [[ "$cur" == .* || "$cur" == /* || "$cur" == ~* ]]; then _filedir "deb" else - COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \ + COMPREPLY=( $( apt-cache pkgnames "$cur" \ 2> /dev/null ) ) fi return 0 @@ -204,7 +205,7 @@ _apt() if [[ "$command" == build-dep && ( "$cur" == .* || "$cur" == /* || "$cur" == ~* ) ]]; then _filedir "dsc" else - COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \ + COMPREPLY=( $( apt-cache pkgnames "$cur" \ 2> /dev/null ) $( apt-cache dumpavail | \ command grep "^Source: $cur" | sort -u | cut -f2 -d" " ) ) fi