Zypper in package name autocompletion in WSL

Hello,

Recently I had to re-install my Windows 10 installation and in turn I had to re-install the OpenSUSE LEAP 15.1 under WSL as well. The new installation seems to not allow auto-completion for the package names for installing packages with zypper in package(tab tab).

Is there a way to turn this on?

Thank you.

Was that ever a feature? I can nit find it in the man page. And I can not realy understand how that would work.

zypper comes with completion function for bash and yes, it works and completes package names. It requires at least one non-dash character though; if you simply press TAB TAB it just completes zypper options, but “zypper in fTAB” will complete package names beginning with “f”.

Pfui, for me that is a bit outside what bash should do. IMHO it should try to complete from the available file names. But I am a bit old-fashioned.

That is what I meant. However bash-completion doesn’t seem to be the right package.

Is there a way to turn this feature “on”? My independent Leap 15.1 install seems to have it, but my WSL LEAP 15.1 doesn’t.

Why not? it is bash you are typing in and only bash can do that completetion. It must of course use some information about which packages exist,

And apparently bash can do context dependent completetion and one can provide plug-ins for the different contexts. There are a lot:

boven:~ # zypper se '*bash-completion'
Loading repository data...
Reading installed packages...

S  | Name                           | Summary                                                    | Type
---+--------------------------------+------------------------------------------------------------+--------
i  | ModemManager-bash-completion   | Bash completion for nmcli                                  | package
   | alacritty-bash-completion      | Bash Completion for alacritty                              | package
i  | bash-completion                | Programmable Completion for Bash                           | package
   | borgbackup-bash-completion     | Bash Completion for borgbackup                             | package
   | bspwm-bash-completion          | Bash Completion for bspwm                                  | package
   | cabal-install-bash-completion  | Bash completion for cabal-install                          | package
   | calf-bash-completion           | Bash completion for calf                                   | package
   | chocolate-doom-bash-completion | Chocolate Doom command line completion support for bash    | package
   | docker-bash-completion         | Bash Completion for docker                                 | package
   | fd-bash-completion             | Bash Completion for fd                                     | package
   | flameshot-bash-completion      | Bash Completion for flameshot                              | package
   | herbstluftwm-bash-completion   | Bash completion for herbstluftwm                           | package
   | imgp-bash-completion           | Bash Completion for imgp                                   | package
   | iproute2-bash-completion       | Bash completion for iproute                                | package
   | kmod-bash-completion           | Bash completion routines for the kmod utilities            | package
   | kopano-bash-completion         | bash TAB completion for Kopano Core command-line utilities | package
   | ldc-bash-completion            | LDC Bash completion                                        | package
   | libvirt-bash-completion        | Bash completion script                                     | package
   | lxc-bash-completion            | Bash Completion for lxc                                    | package
   | lxd-bash-completion            | Bash Completion for lxd                                    | package
i  | mbimcli-bash-completion        | Bash completion for mbimcli                                | package
   | mpv-bash-completion            | Bash Completion for mpv                                    | package
   | patool-bash-completion         | Bash Completion for patool                                 | package
i  | pulseaudio-bash-completion     | PulseAudio Bash completion                                 | package
   | pyenv-bash-completion          | Bash completion for pyenv                                  | package
   | python3-buku-bash-completion   | Bash completion for python3-buku                           | package
   | rclone-bash-completion         | Bash Completion for rclone                                 | package
   | restic-bash-completion         | Bash Completion for restic                                 | package
   | ripgrep-bash-completion        | Bash Completion for ripgrep                                | package
   | salt-bash-completion           | Bash Completion for salt                                   | package
   | subversion-bash-completion     | Bash Completion for subversion                             | package
i  | systemd-bash-completion        | Bash completion support for systemd                        | package
   | systemd-mini-bash-completion   | Bash completion support for systemd                        | package
   | vagrant-bash-completion        | Vagrant bash autocompletion                                | package
   | you-get-bash-completion        | Bash completion for you-get                                | package
i+ | youtube-dl-bash-completion     | Bash completion for youtube-dl                             | package
   | zabbix-bash-completion         | Zabbix bash completion                                     | package
boven:~ # 

(But I do not see a zypplib related one in this list made on Leap 15.1).

What is output of

complete -p zypper

bash-completion is project that provides helpers to create your own completion function as well as completion functions for “common” programs. It is not required to use bash completion, although some projects use its helpers and so require it. Completion for zypper does not use bash-completion at all and does not require it.

~> complete -p zypper
complete -o default -F _zypper zypper

This is correct (assuming _zypper function is correct). Does completion for zypper work at all? What happens when you do “zypper TAB TAB”? Do you have /var/cache/zypp/solv directory and what is its content? zypper completion takes names from there (it should have subdirectory for each repository with solv.idx file).

i do not know how it is implemented nor if the packet/product bash-completion is involved. But it is the bash process that sees your input and your TAB hitting. And it is bash that then must decide that this apparenty in a command that has zypper the first word and thus no normal bash file name completion is needed, but the zypper helper must be asked.

I am so pedantic about this, because I see connections with the misunderstanding that using the wild cards as defined in the zypper documentation must not be treated with care and shielded off from the shell by quoting (notwithstanding the fact that the man page warns for this in several places). When people do not understand which process is in charge at which moment they will never understand why they run into trouble here.

How is it related to the question at all?

Because I have the strong idea that the OP does not see the difference between who is doing what (reading his reamrk about bash-completion not being involved at all). And that does not help in understanding where to search for what. You do understand without me
doubting that.

But I will levae the further solving of this to you.

No, zypper completion does not work, for instance if I do “zypper TAB TAB” I get:

sudo zypper [TAB][TAB]
bin/           .config/       .emacs.d/

which are just directories in my ~/

~> ls /var/cache/zypp/solv
leap-15.1  leap-15.1-update  @System
 ls /var/cache/zypp/solv/leap-15.1*/var/cache/zypp/solv/leap-15.1:
cookie  solv  solv.idx


/var/cache/zypp/solv/leap-15.1-update:
cookie  solv  solv.idx

this is strange, everything is in order and “should” work because I have hte solv.idx for the repositories and everything.

Hi Henk, I was just mentioning that bash-completion not being involved at all just to double/triple check in case I didn’t understand.

Well, devil is in details … you do not complete zypper, you complete sudo. Does it work when you do “zypper TAB TAB”? Does completion for any command work at all (beyond default file names)?

Using zypper [TAB][TAB] seems to have no difference.

In terms of auto-completion, all executables defined in $PATH (in my case /usr/local/bin:/usr/bin:/bin:/usr/lib/mit/bin) seem to autocomplete.

Exactly, and that is why I tried to improve the understanding. Remember I said “… a command that has zypper the first word …” and that is indeed not the case.

I do not have WSL so I cannot test it. As I already said - it is up to you to debug what happens. Run “set -x” and then “zypper TAB” and post output, may be there will be something obvious.

~> set -x~> zypper + local c=
+ local 'a=zypper '
+ local e s cd dc t=
+ local -i o
+ local -i glob=0
+ local -i quoted=0
+ local IFS
+  '' == \" ]]
+ shopt -q extglob
+ (( glob == 0 ))
+ shopt -s extglob
+ cd='*-?(c)d*'
+ dc='*-d?(c)*'
+ case "${1##*/}" in
+ e='!*.+(rpm|you)'
+ case "$(complete -p ${1##*/} 2> /dev/null)" in
++ complete -p zypper
+ s=-S/
+ IFS='
'
+ case "$c" in
+ test '' = ..
+ COMPREPLY=($(compgen -f -X "$e" +o plusdirs -- $c))
++ compgen -f -X '!*.+(rpm|you)' +o plusdirs --
+ test -n ''
+ (( quoted ))
+ _compreply_
+ local 'IFS=
'
+ local s x
+ local -i o
+ local -i isdir=
+ test 0 -eq 0
+ return 0
+ (( glob == 0 ))
+ shopt -u extglob
+ return 0
+ local c=
+ local 'a=zypper '
+ local e s cd dc t=
+ local -i o
+ local -i glob=0
+ local -i quoted=0
+ local IFS
+  '' == \" ]]
+ shopt -q extglob
+ (( glob == 0 ))
+ shopt -s extglob
+ cd='*-?(c)d*'
+ dc='*-d?(c)*'
+ case "${1##*/}" in
+ e='!*.+(rpm|you)'
+ case "$(complete -p ${1##*/} 2> /dev/null)" in
++ complete -p zypper
+ s=-S/
+ IFS='
'
+ case "$c" in
+ test '' = ..
+ COMPREPLY=($(compgen -f -X "$e" +o plusdirs -- $c))
++ compgen -f -X '!*.+(rpm|you)' +o plusdirs --
+ test -n ''
+ (( quoted ))
+ _compreply_
+ local 'IFS=
'
+ local s x
+ local -i o
+ local -i isdir=
+ test 0 -eq 0
+ return 0
+ (( glob == 0 ))
+ shopt -u extglob
+ return 0


bin/           .config/       .emacs.d/      .local/