# Bash Completion for Symfony Console

I got annoyed with the lack of Bash-Completion support for the Symfony Console command and decided to figure out a fix. What I came up with turned out to be pretty simple but perhaps a little sketchy.

A quick search turns up a few standalone commands that can be used with Bash’s complete command but adding a dependency isn’t ideal for me. I dug into how custom completion scripts work and how there are tools provided to parse the normal --help output of commands. Here’s what I came up with. I added the code below to my ~/.bash_completion file and it’s working for me.

There were some hitches I had to get over:

• First, colons are handled as separate tokens so the _get_comp_words_by_ref -n : cur at the start and __ltrim_colon_completions "\$cur" at the end bypass that logic. I found that on SO - not really syre why it works.

• The local cmd=... line is how I’m getting the Symfony command being run but it may not be complete yet; i.e. could be doctrine:. If it ends in a colon, I know it’s not done yet so I can use it to get the help text for options.

• The elif ... clause is how I’m avoiding offering another command name when one has already been given.

All in all, it feels brittle and a little sketchy. YMMV.