How to programmatically query bash completion for given string
Posted
by
Ryan McKay
on Server Fault
See other posts from Server Fault
or by Ryan McKay
Published on 2011-02-04T17:57:14Z
Indexed on
2011/02/04
23:27 UTC
Read the original article
Hit count: 398
bash
|autocomplete
I want to ask bash how it would complete a string as if I had typed it in a shell and hit tab. For example, if I type
ls /[TAB][TAB]
I see the list of files and dirs in / that could possibly complete the ls command. How do I ask bash how it would complete 'ls /' without typing it and hitting tab? I want something like:
query_complete 'partial command line string'
I read the man page for complete and compgen, but couldn't figure out how to do it with them.
Note: 'ls /' is not the actual command I'm interested in, just an example. I am looking for a general solution for any arbitrary string representing a partial command line.
© Server Fault or respective owner