Bash/Shell Autocompletion for Composer

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?
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!

BuymeaCoffee (€3)

To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Unless noted otherwise, the contents of this post are licensed under the Creative Commons Attribution 4.0 License and code samples are licensed under the MIT License

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.