Dnf5 tab completion outputs Error

Edit 2

$ type dnf
dnf is a function
dnf () 
{ 
    if [[ "$1" == "search" ]]; then
        command dnf -q -C search "${@:2}" | grep --color=auto -v 'i686';
    else
        if [[ "$1" == "info" ]] || [[ "$1" == "show" ]]; then
            command dnf -q -C info "${@:2}";
        else
            command dnf -q -C "$@";
        fi;
    fi
}
dnf is /usr/bin/dnf

Edit 1

  • When I typed dnf insta and press TAB key following is printed
$ dnf instaUnknown argument "--complete=1" for command "dnf5". Add "--help" for more information about the arguments.
  • When I typed command dnf inst followed by TAB key:
$ command dnf instUnknown argument "--complete=1" for command "dnf5". Add "--help" for more information about the arguments.

Original

I typed Tab key after ./swhile typing in the following

$ sudo dnf install -y ./sUnknown argument "--complete=3" for command "dnf5". Add "--help" for more information about the arguments.
  • What gets printed - Unknown argument "--complete=3" for command "dnf5". Add "--help" for more information about the arguments.

I cannot reproduce this problem.
I wonder if this depends on what files you have in the current directory?

What does ls "./s*" list?

  • When I typed dnf insta and press TAB key following is printed
$ dnf instaUnknown argument "--complete=1" for command "dnf5". Add "--help" for more information about the arguments.

$ type dnf
dnf is a function
dnf () 
{ 
    if [[ "$1" == "search" ]]; then
        command dnf -q -C search "${@:2}" | grep --color=auto -v 'i686';
    else
        if [[ "$1" == "info" ]] || [[ "$1" == "show" ]]; then
            command dnf -q -C info "${@:2}";
        else
            command dnf -q -C "$@";
        fi;
    fi
}
dnf is /usr/bin/dnf

  • When I typed command dnf inst followed by TAB key:
$ command dnf instUnknown argument "--complete=1" for command "dnf5". Add "--help" for more information about the arguments.

It seems you have defined the dnf function yourself.

I do not have that function on my f41.

Seems you need to port the function to dnf5.

$ dnf --version
dnf5 version 5.2.8.1
dnf5 plugin API version 2.0
libdnf5 version 5.2.8.1
libdnf5 plugin API version 2.0

I am using dnf5 and the defined function is a simple function that should not affect the outcome.

The completion mechanism calls dnf inself to generate the completion using the exact command line

 dnf --complete=1 dnf ins

With your wrapper function this becomes

dnf -q -C --complete=1 dnf ins

which is an error as the argument --complete=1 should be the very first argument to dnf to be recognized. This is documented only in the source code.

I tried the following, it seems to work

	if [[ "$1" == "search" ]]; then
		command dnf -q -C search "${@:2}" | grep -v 'i686'
	elif [[ "$1" == "info" ]] || [[ "$1" == "show" ]]; then
		command dnf -q -C info "${@:2}"
	elif [[ "$1" =~ --complete* ]]; then
		command dnf "$@"
	else
		command dnf -q -C "$@"
	fi

What do you think? Is it fine?

The question should be: “Does it work?”. Thus test it to find out.

1 Like

We had the question lately for the zsh shell and found out that It is not dnf5 ready alias based still on dnf4. Is it ready for bash?
Otherwise this would be an other source of failures/incompatibility.

Topic mentioned is here:
How to get dnf auto completion in zsh