I'd like to customize auto-completion in bash (such as is described at https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Programmable-Completion) such that a parameter can use auto-completion, where the parameter is an expression that should conform to a defined grammar (LALR, PEG or other).
Assuming the grammar definition already exists, is there any way to automate the generation of the resources needed to add this autocomplete capability to bash?
As an example, let's say I have sql.l
and sql.y
which I can compile with flex
and bison
to generate a check_sql
executable that takes a single SQL "select" query as a parameter, and then prints "Valid" or "Invalid" depending on whether the query is valid SQL syntax. Further assume the command syntax is:
check_sql <sql query>
Then, if I typed in:
check_sql "sel
and then hit Tab, I would like autocomplete to propose to add "ect" to finish the word "select".
Similarly, if I typed in:
check_sql "select my_column from my_table
and then hit Tab, I would like autocomplete to show options such as "where", "inner", or "having".
Finally, I would like to generate the scripts and resources that implement this behavior, using sql.l, sql.y or both as inputs, so that if/as my grammar definition files change, it is easy to also update the bash completion resources.
Is this possible and/or feasible? I have used this approach to implement autocomplete using Monaco (with a PEG grammar rather than an LALR one)-- and it seems in theory that it shouldn't be too hard to do with bash autocomplete, but I'm not finding any relevant documentation or examples.