I would like to be able to use tab auto completion with composer in my bash shell, the same way I can for example auto complete filenames or git commands.
To enable auto complete for composer
in bash you need to write a function that returns an array of possible values for the last typed parameter (_composer()
in this case) and register it using complete -F function command
.
As a complete, working example add the following to your .bashrc
(or any other configuration script you might be using)
_composer()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local cmd=${COMP_WORDS[0]}
if ($cmd > /dev/null 2>&1)
then
COMPREPLY=( $(compgen -W "$($cmd list --raw | cut -f 1 -d " " | tr "\n" " ")" -- $cur) )
fi
}
complete -F _composer composer
complete -F _composer composer.phar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With