Thursday, 16 May, 2019 UTC


Summary

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 →
Did this help you out? Like what you see?
Consider donating.
I don’t run ads on my blog nor do I do this for profit. A donation however would always put a smile on my face though. Thanks!
Buy me a Coffee ($3)