1. Home

Anil

< Blog />

Auto completion for the Symfony console command

in

Symfony’s Console component and the commands provided by Symfony framework are one of my favourite things about Symfony, it can help to quickly bootstrap a new project or perform tasks whilst maintaining an existing one.

This was a script I came across on Github to enable Symfony console auto complete for all projects without adding any additional code to your projects.

Say I started typing app/console cacTAB, this script would allow me to auto complete the cache command or view the available commands. This also works for your own console commands on a per project basis.


Copy the file to your local machine

CURL the following file to your local machine. I keep mine in ~/Console.

curl https://raw.githubusercontent.com/jaytaph/SFConsole/master/console_completion.sh > console_completion.sh

Source it in your .bash_profile

In your .bash_profile add the following:

# Symfony Console completion helper
# https://github.com/jaytaph/SFConsole
source ~/Console/console_completion.sh

Reload your source

Restart your terminal (close it and open a new session - or reload your source via source ~/Console/console_completion.sh)


Play with it!

Now, navigate to a Symfony app, and try it..

app/console cac<tab>
# Notice it completes to `app/console cache:`

# Press <tab><tab> again to view the available commands
cache:clear   cache:warmup

or

app/console doc<tab>
# turns into `app/console doctrine:`

# Press <tab><tab> again to view the available `doctrine` commands
# (.. all the doctrine commands will display)