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
FIX: out of date external completion examples (#923)
* fix the multi-completer external completion
* use the new mutable `$env.* = ...` syntax
* use 4 spaces indentation in the multi-completer example
* define completers and add note about how to configure any of them
Copy file name to clipboardexpand all lines: book/custom_completions.md
+25-32
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,7 @@ module commands {
54
54
def animals [] {
55
55
["cat", "dog", "eel" ]
56
56
}
57
-
57
+
58
58
def animal-names [context: string] {
59
59
{
60
60
cat: ["Missy", "Phoebe"]
@@ -140,55 +140,48 @@ External completers can also be integrated, instead of relying solely on Nushell
140
140
For this set the `external_completer` field in `config.nu` to a block which will be evaluated if no Nushell completions were found.
141
141
You can configure the block to run an external completer, such as [carapace](https://github.com/rsteube/carapace-bin).
142
142
143
+
> **Note**
144
+
> in the following, we define a bunch of different completers.
145
+
>
146
+
> one can configure them in `$nu.config-path` as follows:
147
+
>
148
+
> ```nu
149
+
> $env.config.completions.external = {
150
+
> enable: true
151
+
> max_results: 100
152
+
> completer: $completer
153
+
> }
154
+
> ```
155
+
143
156
This example should enable carapace external completions:
144
157
145
158
```nu
146
-
# config.nu
147
159
let carapace_completer = {|spans|
148
160
carapace $spans.0 nushell $spans | from json
149
161
}
150
-
151
-
# The default config record. This is where much of your global configuration is setup.
152
-
let-env config = {
153
-
# ... your config
154
-
completions: {
155
-
external: {
156
-
enable: true
157
-
max_results: 100
158
-
completer: $carapace_completer
159
-
}
160
-
}
161
-
}
162
162
```
163
163
164
164
Multiple completers can be defined as such:
165
165
166
166
```nu
167
-
let external_completer = {|spans|
168
-
{
169
-
$spans.0: { default_completer $spans | from json } # default
170
-
ls: { ls_completer $spans | from json }
171
-
git: { git_completer $spans | from json }
172
-
} | get $spans.0 | each {|it| do $it}
167
+
let multiple_completers = {|spans|
168
+
{
169
+
$spans.0: { default_completer $spans | from json } # default
170
+
ls: { ls_completer $spans | from json }
171
+
git: { git_completer $spans | from json }
172
+
} | each {|it| do $it}
173
173
}
174
174
```
175
175
176
176
This example shows an external completer that uses the `fish` shell's `complete` command. (You must have the fish shell installed for this example to work.)
177
177
178
178
```nu
179
179
let fish_completer = {|spans|
180
-
fish --command $'complete "--do-complete=($spans | str join " ")"' | str trim | split row "\n" | each { |line| $line | split column "\t" value description } | flatten
181
-
}
182
-
183
-
let-env config = {
184
-
# ... your config
185
-
completions: {
186
-
external: {
187
-
enable: true
188
-
max_results: 100
189
-
completer: $fish_completer
190
-
}
191
-
}
180
+
fish --command $'complete "--do-complete=($spans | str join " ")"'
181
+
| str trim
182
+
| split row "\n"
183
+
| each { |line| $line | split column "\t" value description }
0 commit comments