When I first saw Fig mentioned on Twitter (I think it was) I was really interested - autocomplete for command line commands. Yes, please! The developers also made it easily extendable - actually, that's the core aim: allow specs to be written and contributed to help the available autocomplete commands grow. After all, there are so many commands the devs would be trying to scour otherwise.
artisan command is one of the autocomplete specs for Fig. In your terminal - be that something like Hyper or even bare bones macOS Terminal - you start typing and you get suggestions:
Pretty neat, hey?
Looking at the source code for the
artisan spec, it's actually really neat under the hood. Rather than hard-coding all of the commands, options and arguments, the spec is only included if
artisan is in the current path, and then loads the spec using the
list command, output as JSON:
php artisan list --format=json
The spec reads the JSON output, and dynamically builds the commands with options, arguments and descriptions based on what Laravel is saying is available. Meaning that if you have custom commands, they'll appear. If Laravel adds new ones, they'll appear. It's such a smart and logical approach.
please has a similar
list option, I started building a spec based on the
artisan one that instead is asking nicely:
php please list --format=json
Once again, if there are custom commands within your Statamic install, they'll appear. If Statamic add new commands, they'll appear. And it is only included if
please is found in the current directory too.
So let's give it a spin:
How flipping cool is this? Fig is such a handy tool to have installed, just for those little brain fart moments where you can't quite remember the exact syntax. And writing a spec - even though it is based on the existing
artisan one, so full credit to the original authors for the base - is actually really straight-forward.
One thing that is missing is a little 'Statamic' icon - like how the
artisan one has the Laravel 'L' icon. I'd love to add something like this, but maybe the Statamic team want to give the a-ok on that - it is their brand mark after all, and I didn't want to tread on toes.
please. Or something else. Fig is a great tool, and after being put off by previous experiences contributing to a different and specific open source project (but let's leave that for another day) am a bit chuffed of having this PR merged.
Already got Fig, don't forget to update: