I have made a script that lists available projects. You can start a project by entering script start <project>
.
Now it would be great to enable autocompletion, so if you're entering start Organ
and press TAB
, it autocompletes to start Organisation
.
The difficult part is that the list of projects is dynamic. The list of available projects changes frequently and all users have different available projects.
My idea was to save the available projects into a json file and use this file to enable the autocompletion. I know that I have to create a file in /etc/bash_completion.d/
, but I don't know how I can implement a "dynamic" autocompletion that depends on the available projects.
Best Answer
Let assume you have a script called
output_projects
that lists all available projects. Now call it from a bash function:Now bind it to
start
like in our example with something like this:Basically, each time you press
<tab>
bash will execute the function and get a fresh list of available projects.Tested on:
Did that solve your problem? If not please rephrase and clarify what you was looking after.