You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/custom_completions.md
+6-4Lines changed: 6 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ my-command
21
21
The first line defines a custom command which returns a list of three different animals. These are the possible values for the completion.
22
22
23
23
::: 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 (`[ ]`).
25
25
:::
26
26
27
27
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
32
32
When the completion menu is displayed, the prompt changes to include the `|` character by default. This can be changed using `$env.config.menus.marker`.
33
33
:::
34
34
35
+
::: tip
36
+
To fall back to Nushell's built-in file completions, return `null` rather than a list of suggestions.
37
+
:::
38
+
35
39
## Options for Custom Completions
36
40
37
41
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:
You can configure the closure to run an external completer, such as [carapace](https://github.com/rsteube/carapace-bin).
214
218
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.
218
220
219
221
::: tip Note
220
222
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