Statamic 3's 'please' spec for Fig

Published October 1st, 2021

Important: The information in this article is over 12 months old, and may be out of date or no longer relevant.

But hey, you're here anyway, so give it a read see if it still applies to you.

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.

Laravel's 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:

An animated GIF demonstrating using Fig with an Artisan command

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:

1php artisan list --format=json
Copied!

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.

Given please has a similar list option, I started building a spec based on the artisan one that instead is asking nicely:

1php please list --format=json
Copied!

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:

An animated GIF demonstrating using Fig with a Statamic 3 please command

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.

Maybe it's cd, ls, git, artisan or 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:

1fig update
Copied!

New to Fig? Head over to fig.io and jump on the list to get an invite. I do have a couple of invites available if you're interested too - reach out to me on Twitter.

You may be interested in...