bash-completion
bash-completion copied to clipboard
man xyz stays xy if directory with same name present
$ man apti<TAB>
correctly becomes
$ man aptitude
aptitude aptitude-create-state-bundle aptitude-curses aptitude-run-state-bundle
However
$ mkdir /tmp/aptitude
$ cd /tmp/
$ man apti<TAB>
aptitude/ aptitude/ aptitude-create-state-bundle aptitude-curses aptitude-run-state-bundle
- Does not at least complete to "aptitude", but instead stays "apti".
- Gives two "aptitude/"
Reproduced, interesting.
A real world example: Ubuntu switched from deb to snap for browser packages (firefox, chromium), so users almost inevitably have ~/snap/ folder. A command to manage these packages is named snap as well. If CWD is ~ then hitting TAB while typing man snap causes manifestation of this issue.
I don't have good ideas offhand how to fix this.
Getting rid of the duplicate would be fairly easy, but it'd get rid of the command, leaving only the dir with the trailing slash present. I think this is not what people would generally expect.
We could opt to not completing filenames if we've found some completions already. PR #787 implements that, at the expense of not doing filename completions at all if a matching man page from manpath has already been found. I'm not entirely happy with that either, because it will hurt also the vast majority of use cases where there are no problematic duplicates present. Then again, the use case mostly affected by this would be the second manpage argument to man and subsequent ones, which is a quite rare one.
A workaround to force filename completion is M-/, so ./ prefix is not necessary. However the problem of combining filename and non-filename completions is more general, see e.g. scp where colon without space should be added to host names while files and directories should be handled accordingly to regular rules. Unfortunately the scp code is not really robust.