Fig supports building autocomplete for internal scripts (executables) like
build.js. Assuming these scripts each take different arguments, subcommands, and flags, Fig can be used to build autocomplete for these scripts to make it easy for your team to use them.
You can clone our boilerplate repo to write and test and internal spec using our autocomplete-tools package on npm:
npx -y @withfig/autocomplete-tools init
This will create a boilerplate directory
.fig/autocomplete in your current
directory like our autocomplete repo but without the public specs.
Now that you have the boilerplate directory, you can
cd into this directory
cd .fig/autocomplete and you'll have a nice developer environment set up by default.
When developing a spec, turn on Fig development mode by running
npm run dev from your autocomplete folder. This should generate a
src/ folder in the root of your autocomplete folder.
Development mode compiles all changes from the
src/ folder into specs that can be read by Fig, and tells Fig to load specs from the
build/ folder. (If you don't see
build/ yet, it will be generated upon making changes to any file in
src/) This means you can test your internal CLI from your terminal in real time!
Create a TypeScript file in the
src/ folder for the internal command you're building for. Write your spec in this folder, and make changes in
src/. All changes to files in
src/ will be compiled to
We write our specs in the autocomplete folder to get access to linting and live testing. Now, we need to move the compiled specs from
/build into your scripts folder for usage.
In the same directory as your scripts, create a
.fig directory. The
.fig directory should contain an autocomplete spec for each script you want to generate suggestions for.
From the autocomplete directory, take the compiled specs from
build/ and move them into the
.fig directory of your scripts directory.
Note: the naming of these specs is important! They should exactly match
[script].js. If you wanted to write a spec for
deploy.py, name it
The folder hierarchy should look like this:
|-- dev.sh |-- deploy.py |-- tests.js |-- .fig/ |-- autocomplete/ |-- src/ |-- dev.sh.ts |-- deploy.py.ts |-- test.js.ts |-- build/ |-- dev.sh.js |-- deploy.py.js |-- test.js.js
Your scripts directory containing
.fig can be shared with teammates, who will automatically get autocomplete for these scripts if they have Fig installed. Want to get your teammates onboard? Run
fig invite in your CLI!
Looking to build comprehensive internal CLIs for your team with Fig? See Building Autocomplete for Internal CLIs.