Ubuntu 20.04: su command bash-autocomplete stopped working

I am using Ubuntu 20.04. The su autocomplete stopped working. For example when I type:

su TabTab

It lists the files and directories of the current directory, where as it should list the available users.

Bash auto-complete for other commands is working fine for example:

apt-get TabTab

It lists the available apt-get options.

usermod TabTab

It lists the available user accounts.

su was working fine before and now it is not. I have no idea when it stopped working.

I have checked other questions but most of them are related to bash-completion, not specific to su. So, before marking it duplicate please check the existing answer if it addresses su.


Finally found the solution.

It is not an issue but due to the changes in the implementation of su command on Ubuntu-20.04.

Here is the workaround:

Edit the following file:

sudo vi /usr/share/bash-completion/completions/su

Replace line 44:

COMPREPLY=( $(compgen -f -- $cur) )

with

COMPREPLY=( $(compgen -u -- $cur) )

Source-1: https://stackoverflow.com/a/53417028/8388883

Source-2: https://github.com/scop/bash-completion/issues/253#issuecomment-440591431

The sources are for CentOS, but also working for Ubuntu 20.04.