Docs›Generator›Prebuilt generators
Prebuilt Generators
Some generators are used in many different specs but not enough to be included directly into the Fig source code, so we created an npm package to collect them.
@fig/autocomplete-generators
This package is already added as a dependency in the autocomplete
repo and using it in a completion spec is as simple as importing it.
import { filepaths } from "@fig/autocomplete-generators"
The generators imported from this packages are only bundled in the specs that import them so everything stays as lightweight as possible.
Exported generators
filepaths([options])
Adds more control over the suggested files and folders allowing to filter them or perform fast edits to the generated suggestions.
Example: filter by extension
const completion: Fig.Spec = {
name: "python3"
// ...rest of the completion
args: {
generators: filepaths({
extensions: ["py"], // this will suggest all the filepaths in the current directory that has `.py` as the extension
})
}
}
Example: edit the file suggestions and do not suggest folders
filepaths({
editFileSuggestions: { priority: 76, icon: 'some_icon_path.png' },
suggestFolders: 'never',
})
Example: edit the folder suggestions and filter files by name
filepaths({
equals?: ['foo.txt'],
matches: /bar/g,
editFileSuggestions: { priority: 25 },
})
NOTE: if either
equals
ormatches
criteria matches the suggestion gets displayed
Example: filter files AND folders by name
filepaths({
suggestFolders: 'filter',
equals?: ['foo.txt', 'foo'],
matches: /bar/g,
})
keyValue([options])
Create a generator that gives suggestions for key=value arguments.
Example: add a key-value generator
// cli a=1 b=3 c=2
const spec: Fig.Spec = {
name: "cli",
args: {
name: "values",
isVariadic: true,
generators: keyValue({
keys: ["a", "b", "c"],
values: ["1", "2", "3"],
}),
},
}
Example: specify a custom separator and cache suggestions
// key1:value
keyValue({
separator: ":", // this defaults to an equal (=)
keys: [
{ name: "key1", icon: "fig://icon?type=string" },
{ name: "key2", icon: "fig://icon?type=string" },
],
cache: true,
}),
NOTE: if
keys
orvalues
is omitted
keyValueList([options])
An extension of keyValue
that also accept multiple key-values separated by a character (e.g. cli app:prod,test:beta,ci:beta
)
Example: add a key-value list generator with cache
keyValue({
separator: ":", // this defaults to an equal (=)
delimiter: "," // this defaults to a comma (,)
keys: ["app", "test", "ci"],
values: ["prod", "staging", "beta"],
cache: true,
}),
Contribute to the package
You can contribute with your own generators here by opening a PR in the autocomplete-tools
repo on GitHub.