dnf install foo<TAB> does not work

Issues related to applications and software problems and general support
Post Reply
search4workingdistro
Posts: 66
Joined: 2020/11/18 10:52:19

dnf install foo<TAB> does not work

Post by search4workingdistro » 2021/10/23 17:53:31

When I type in the command line

Code: Select all

dnf install foo
and press Tab, I expect to see the packages with names starting with foo but instead it just freezes and I need to abandon that terminal tab and open a new one to continue.
How do I fix that?

User avatar
TrevorH
Site Admin
Posts: 33191
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: dnf install foo<TAB> does not work

Post by TrevorH » 2021/10/23 18:05:19

I am not aware that any command line completion can possibly complete the names of the packages you want to list. It doesn't know what they are. The names are all in the dnf repodata which could either be not present, stale or current. It would need to be current to be able to be used but then bash would have to interrogate the dnf API to list the them.

I think you're expecting the impossible.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

search4workingdistro
Posts: 66
Joined: 2020/11/18 10:52:19

Re: dnf install foo<TAB> does not work

Post by search4workingdistro » 2021/10/23 21:12:18

TrevorH wrote:
2021/10/23 18:05:19
I think you're expecting the impossible.
Somehow it worked on all debian-based distros I used in the past. And I believe it worked on my CentOS8 when it was just installed but then it got broken.

Mike_Rochefort
Posts: 215
Joined: 2016/03/16 02:34:19

Re: dnf install foo<TAB> does not work

Post by Mike_Rochefort » 2021/10/23 22:33:01

To my knowledge Debian based distributions always work off a local cache and don't update it unless explicitly told (at least with apt-get). dnf does as well, but will always perform a check to determine whether or not to update the local cache. I have package completion working in a Stream 8 container by:

1) Making sure bash-completion was installed, and
2) Running dnf makecache to generate up-to-date repo cache information.

After that, running dnf install python<TAB><TAB> would list out available packages for install. It uses the same output setup as more, so it's not an ideal tool for situations where many packages share the same prefix.

However, this methodology is a bit finicky. You're better off using subcommands like search and list paired with the -C flag (capital C, which will use the local cache rather than updating it) to look for packages to pass to a dnf install run than relying on tab completion. The local cache flag is not allowed with install, and metadata will always be checked and updated if need be.

For example:

Code: Select all

$ dnf makecache # Initial cache

$ dnf -C search zstd
======= Name & Summary Matched: zstd =======
zstd.x86_64 : Zstd compression library
libzstd.x86_64 : Zstd shared library
libzstd.i686 : Zstd shared library
libzstd-devel.i686 : Header files for Zstd library
libzstd-devel.x86_64 : Header files for Zstd library

$ dnf -C list python*devel
Available Packages
python2-cairo-devel.x86_64      1.16.3-6.module_el8.0.0+36+bb6a76a2        appstream
python2-devel.x86_64            2.7.18-8.module_el8.6.0+940+9e7326fe       appstream
python36-devel.x86_64           3.6.8-38.module_el8.5.0+895+a459eca8       appstream
python38-devel.x86_64           3.8.12-1.module_el8.6.0+929+89303463       appstream
python39-devel.x86_64           3.9.7-1.module_el8.6.0+930+10acc06f        appstream
Glob expressions are supported as demonstrated above, along with filters like --installed and --available for list to keep output tidy (see more options in the dnf(8) man pages).

Cheers,
Mike
Solution Architect @RedHat | RHCE
Former SysAdmin @BlueSkyStudios and @Pixar
Feature animation and VFX enthusiast
--
Report CentOS Stream 8 bugs: https://da.gd/c8s-bugs
Report CentOS Stream 9 bugs: https://da.gd/c9s-bugs

search4workingdistro
Posts: 66
Joined: 2020/11/18 10:52:19

Re: dnf install foo<TAB> does not work

Post by search4workingdistro » 2021/10/24 07:40:51

Mike_Rochefort wrote:
2021/10/23 22:33:01
1) Making sure bash-completion was installed, and
2) Running dnf makecache to generate up-to-date repo cache information.
Did that but pressing tab button still just freezes a terminal tab.
Mike_Rochefort wrote:
2021/10/23 22:33:01
However, this methodology is a bit finicky. You're better off using subcommands like search and list paired with the -C flag (capital C, which will use the local cache rather than updating it) to look for packages to pass to a dnf install run than relying on tab completion. The local cache flag is not allowed with install, and metadata will always be checked and updated if need be.
Tabbing may not be ideal but my brain is small and can only remember this trick and it helps in 99.9% of cases.

sml
Posts: 305
Joined: 2020/01/17 09:01:44

Re: dnf install foo<TAB> does not work

Post by sml » 2021/10/24 17:58:38

It works on my CentOS 8 installation, but takes a long time. So long in fact, that I usually interrupt it with Ctrl+C when I accidentally hit Tab after dnf in.

To compare, there's hardly a delay when I do the same with apt in Debian.

owl102
Posts: 413
Joined: 2014/06/10 19:13:41

Re: dnf install foo<TAB> does not work

Post by owl102 » 2021/10/24 19:05:42

sml wrote:
2021/10/24 17:58:38
To compare, there's hardly a delay when I do the same with apt in Debian.
I guess that dnf does update its meta data first which is IMHO a design flaw. If they offer bash tab completion, they should do it without updating the cache. (dnf offers the option --cacheonly to do so, therefore I assume the bash tab completion could use that option.)
German speaking forum for Fedora and CentOS: https://www.fedoraforum.de/

search4workingdistro
Posts: 66
Joined: 2020/11/18 10:52:19

Re: dnf install foo<TAB> does not work

Post by search4workingdistro » 2021/10/28 23:04:45

owl102 wrote:
2021/10/24 19:05:42
I guess that dnf does update its meta data first which is IMHO a design flaw. If they offer bash tab completion, they should do it without updating the cache. (dnf offers the option --cacheonly to do so, therefore I assume the bash tab completion could use that option.)
Is there a way to fix it?

sml
Posts: 305
Joined: 2020/01/17 09:01:44

Re: dnf install foo<TAB> does not work

Post by sml » 2021/10/29 13:15:22

owl102 wrote:
2021/10/24 19:05:42
I guess that dnf does update its meta data first which is IMHO a design flaw. If they offer bash tab completion, they should do it without updating the cache. (dnf offers the option --cacheonly to do so, therefore I assume the bash tab completion could use that option.)
Actually, it does use this option. This is how the function _dnf_commands_helper looks like in /usr/share/bash-completion/completions/dnf:

Code: Select all

_dnf_commands_helper()
{
    local helper_cmd="import sys; from dnf.cli import completion_helper as ch; ch.main(sys.argv[1:])"
    local helper_opts="-d 0 -q -C --assumeno --nogpgcheck"
    echo "$( ${__dnf_python_exec} -c "$helper_cmd" "$@" $helper_opts 2>/dev/null </dev/null )"
}
Note the -C in helper_opts.

Post Reply