Bash perldoc completion tweaks

Remember when I wrote the following?

Completion in bash is hard-wired to understand trailing slashes as “the user might want to do more completion right after this” – we want :: treated that way instead but there is no way to tell bash.

This is still true, but reading the manpage a little less carelessly reveals that passing -o nospace to the complete command tells bash to simply never append a space, which achieves what is desired without hacks.

While I was in there, I found -o default, which means that if the completion generator returned no results, bash should use its default completion generator instead. This is very useful.

Previously, with “.” in your @INC (as it commonly is), all directories directly inside the current working directory would be included in the completions list as suggested namespaces, because perldoc-complete has no way of knowing which of them contain modules and which don’t. (It would have to recurse, which is too expensive.) But since there is a way to fall back to bash’s default filesystem completion, I have added an extra check that removes not only the home directory from @INC, but the current directory as well.

If you want to complete on documentation in modules somewhere below the current directory, simply type perldoc ./<Tab> etc to use standard path completion. Or perldoc /<Tab> to complete on an absolute path.

Share and enjoy.


  • No more ugly fake suggestions to force ambiguity
  • No more spurious namespace suggestions outside your home directory
  • You can now complete on paths as well as namespaces by starting the path with / or ./
  • Existing users will have to change their .bashrc line to
    complete -C perldoc-complete -o nospace -o default perldoc


Thanks, this is a great feature. There is a case that is a little irritating, though. My PERLLIB env var has "/usr/app/Local", and the expansion works great for the modules in that directory - unless my current directory is "/usr/app", which it frequently is. Other than that, it's perfect! Thanks!

Leave a comment

About Aristotle

user-pic Waxing philosophical