szermatt / emacs-bash-completion

Add programmable bash completion to Emacs shell-mode
GNU General Public License v2.0
279 stars 33 forks source link

bash-completion.el (bash-completion-comm): Add delete-dups #26

Closed abo-abo closed 6 years ago

abo-abo commented 6 years ago

The "compgen" utility will sometimes produce a duplicate with the first and the second cands being equal.

szermatt commented 6 years ago

This takes care of the main path, but not the default completion path (bash-completion--default-completion), which also processes compgen output. bash-completion-extract-candidates would be a better place to put the call to delete-dups - this is, after all, the function that processes the output.

I see nothing wrong with getting rid of duplicate; it's never going to be useful. However, I find it puzzling that there would be a need for it. I never saw compgen behave that way. Would you have more details on how to reproduce the behaviour? What version of bash are you using? Does it happen for all completion, or just a specific one? What's the compgen configuration for that command (complete -p | grep ${thatcommand}) ? It could be just a bad completion function.

abo-abo commented 6 years ago
compgen -b -c -a -A function -- ma 2>/dev/null

Results in ("mapfile" "mapfile" ...).

szermatt commented 6 years ago

Hehe, yes, all it takes is a duplicate entry in the PATH. This is silly :) Thank you letting me know.

De-duplication is clearly needed, especially in bash-completion--default-completion.

abo-abo commented 6 years ago

Thanks.