friends-of-presta / fop_console

Prestashop Module providing a set of shell/terminal commands for developers (PrestaShop 1.7.5+)
Academic Free License v3.0
84 stars 35 forks source link

Study auto completion #56

Open nenes25 opened 4 years ago

nenes25 commented 4 years ago

Check if it is possible to implement autocompletion Thanks to @SebSept idea : https://github.com/stecman/symfony-console-completion If not what about a pull request on PS projetct ?

SebSept commented 3 years ago

Autocompletion depend on the shell (bash, zsh, fish, ...) and require operation on the user's machine file. It might be a bit complicated to submit this to the PS project... Maybe not, I'm not used to contribute du Prestashop core.

SebSept commented 3 years ago

Inspired by the zsh robo plugin. I managed to have autocompletion running 😄 (commands only, not arguments/parameters) with this : create file fop_compl.sh :

_fop_get_command_list () {
    php72 ./bin/console --no-ansi | sed "1,/Available commands/d" | awk '/ ([a-z]+)/ { print $1 }'
}

_fop () {
        compadd `_fop_get_command_list`
}

compdef _fop php72 ./bin/console
source fop_compl.sh

No change in fop_console code required. It works.

Note : For a daily usage, it should be linked/sourced in the ~/.zshrc (via plugin maybe). This example runs on my machine where I have multilple php binaries. You may need to replace php72 with php.


However, using https://github.com/stecman/symfony-console-completion may be a better choice because of arguments completion. But it requires fop_console commands to implement special methods for arguments completion. (and also a user system modification (for sourcing)).

SebSept commented 2 years ago

By the way, Symfony 5.4 & 6.0 will have autocompletion. https://symfony.com/blog/new-in-symfony-5-4-console-autocompletion