Custom completions

    There are two parts to a custom command: the command that handles a completion and attaching this command to the type of another command using @.

    Let’s look at an example:

    In the first line, we create a custom command that will return a list of three different animals. These are the values we’d like to use in the completion. Once we’ve created this command, we can now use it to provide completions for other custom commands and externs.

    On the third line, we type the name of our custom command followed by hitting space and then the <tab> key. This brings up our completions. Custom completions work the same as other completions in the system, allowing you to type e followed by the <tab> key and get “eel” automatically completed.

    You may prefer to keep your custom completions away from the public API for your code. For this, you can combine modules and custom completions.

    Let’s take the example above and put it into a module:

    This is possible because custom completion tags using @ are locked-in as the command is first parsed.

    A powerful combination is adding custom completions to known extern commands. These work the same way as adding a custom completion to a custom command: by creating the custom completion and then attaching it with a to the type of one of the positional or flag arguments of the extern.

    If you look closely at the examples in the default config, you’ll see this: