You normally interact with bash completion by pressing the tab key in your terminal. I would like to interact with it within a script of mine. Essentially, I would like a function/command that answers the question "If I pressed tab with text xyz already typed and the cursor as position n, what would be the suggestions?"
Does this function exist? I found compgen but it's poorly documented and doesn't seem to do what I want.
The
compgenseems to be exactly what you'd like to use anyway. To display what would happen if you'd be typingcomand hitting the TAB key, use:Or:
This will output all Bash builtins along with external binaries and scripts found from the
PATH.More information can be found from the documentation in case you'd like to, for example, prune out from the output of
compgenall Bash builtins and display just the external binaries/scripts.