Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony Console tab completion

I have an application with a Symfony Console based CLI. The application does not use the Symfony framework, just the Symfony Console component.

When I execute

php app/myapp

I get the usual overview with the name, version, options and registered commands shown. Suppose I just have one command, called "displaykittens". What I want to be able to do is

php app/myapp d <TAB>

And have it complete to

php app/myapp displaykittens

As is kinda expected in a modern unix environment. Unfortunately there appears to be no tab completion whatsoever. The Console Component itself provides an utility that allows doing something along these lines in commands themselves. That does not help me with getting tab completion for the commands though. Is this possible somehow?

like image 571
Jeroen De Dauw Avatar asked Oct 22 '25 13:10

Jeroen De Dauw


1 Answers

Symfony 5.4+ has autocompletion natively. You can get more information about autocompletion with bin/console completion --help.

For example with bash you can add this in your ~/.bashrc.

eval "$(/var/www/app/bin/console completion bash)"

Official announcement: https://symfony.com/blog/new-in-symfony-5-4-console-autocompletion

like image 165
Fabien Sa Avatar answered Oct 25 '25 03:10

Fabien Sa