Skip to content

Commit f3dd225

Browse files
authored
Document file completion fallback for custom/external completers (#1759)
* Note file completion fallback * Mention null fallback for external completers too
1 parent a2e658a commit f3dd225

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

book/custom_completions.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ my-command
2121
The first line defines a custom command which returns a list of three different animals. These are the possible values for the completion.
2222

2323
::: tip
24-
To suppress completions for an argument (for example, an `int` that can accept any integer), define a completer that returns an empty list (`[ ]`). At the moment, invalid values such as `null` will also suppress completions, but this may change in the future.
24+
To suppress completions for an argument (for example, an `int` that can accept any integer), define a completer that returns an empty list (`[ ]`).
2525
:::
2626

2727
In the second line, `string@animals` tells Nushell two things—the shape of the argument for type-checking and the completer which will suggest possible values for the argument.
@@ -32,6 +32,10 @@ The third line is demonstration of the completion. Type the name of the custom c
3232
When the completion menu is displayed, the prompt changes to include the `|` character by default. This can be changed using `$env.config.menus.marker`.
3333
:::
3434

35+
::: tip
36+
To fall back to Nushell's built-in file completions, return `null` rather than a list of suggestions.
37+
:::
38+
3539
## Options for Custom Completions
3640

3741
If you want to choose how your completions are filtered and sorted, you can also return a record rather than a list. The list of completion suggestions should be under the `completions` key of this record. Optionally, it can also have, under the `options` key, a record containing the following optional settings:
@@ -212,9 +216,7 @@ $env.config.completions.external = {
212216

213217
You can configure the closure to run an external completer, such as [carapace](https://github.com/rsteube/carapace-bin).
214218

215-
When the closure returns unparsable json (e.g., an empty string) it defaults to file completion.
216-
217-
An external completer is a function that takes the current command as a string list, and outputs a list of records with `value` and `description` keys, like custom completion functions.
219+
An external completer is a function that takes the current command as a string list, and outputs a list of records with `value` and `description` keys, like custom completion functions. When the closure returns `null`, it defaults to file completion.
218220

219221
::: tip Note
220222
This closure will accept the current command as a list. For example, typing `my-command --arg1 <tab>` will receive `[my-command --arg1 " "]`.

0 commit comments

Comments
 (0)