The other day I opened up a PHP project that I hadn’t worked on in a while. No longer remembering which Composer Scripts I had defined for it, I needed to take a peek inside composer.json
to see which ones were available to me. Then it hit me: why is there no autocompletion for composer
available?
Googling around a bit I eventually turned to creating my own Bash completion script for Composer. After installing it, it will autocomplete composer commands for you:
$ composer in[TAB][TAB]
info init install
💡 Want to build your own bash completion script? This very good tutorial has got you covered.
The code builds further upon this earlier work by Rob Allen. Key area where it differs from Rob’s work is that composer-autocomplete
also provides autocompletion for composer run-script
, listing which Composer Scripts are available to you (as I initially wanted).
{
"name": "bramus/example-php-package",
"description": "Example PHP Package",
"type": "library",
"license": "MIT",
…
"scripts": {
"test": "./vendor/bin/phpunit --colors=always",
"lint": "php-cs-fixer fix --diff --dry-run --ansi",
"fix": "php-cs-fixer fix"
}
}
$ composer run-script [TAB][TAB]
fix lint test
Bash/Shell Autocompletion for Composer →
Thank me with a coffee.
I don\'t do this for profit but a small one-time donation would surely put a smile on my face. Thanks!
To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.