Question: I have a question that is apparently not answered by this already-asked Bash completion question on Stack Overflow. The question is, how to get Bash alias completion (for any alias) on a partial substring.
Example: For example, assume I have the following aliases:
open.alicehome='cd /usr/home/alice' open.bakerhome='cd /usr/home/baker' open.charliehome='cd /usr/home/charlie' gohomenow='shutdown -now'
I would like to lazily just type ‘baker{{TAB}}’ to invoke the second alias.
I would like to lazily just type ‘home{{TAB}}’ to get a list of all of the above aliases that I can then choose from with the keyboard (optimal) or choose by typing an unambiguous substring that distinguishes among the three options (less than optimal).
.. OR ..
I would like to lazily just type ‘home’ and then repeatedly press {{TAB}} until the specific alias I want shows up, then press {{ENTER}} to execute it.
Feel free to be creative: If you have a way to do this, even if it requires resorting to extreme guru hackery, please feel free to share it and feel free to explain your guru hackery to the level of a five-year-old who will have to try to implement your idea for himself.
Links to existing web-pages or RTFMs are welcome.
You can generate the matches for a specified substring with
compgen -c -X'!*substring*'To include this in bash autocompletion you can create a .bash_completion file in your home directory containing something like this:
This match function will run when you press
<TAB>on the arguments to theevalcommand. I haven’t found a way to include a new matching function for the first command search in bash, I’ve only found documentation on how to add custom completions for a specific command, likeevalabove.But I’m a bit skeptical to how useful this is… There is no easy way to select which match you want from the list.