Skip to content

Commit 37ae5eb

Browse files
authored
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
1 parent 6a63558 commit 37ae5eb

File tree

1 file changed

+25
-32
lines changed

1 file changed

+25
-32
lines changed

book/custom_completions.md

+25-32
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module commands {
5454
def animals [] {
5555
["cat", "dog", "eel" ]
5656
}
57-
57+
5858
def animal-names [context: string] {
5959
{
6060
cat: ["Missy", "Phoebe"]
@@ -140,55 +140,48 @@ External completers can also be integrated, instead of relying solely on Nushell
140140
For this set the `external_completer` field in `config.nu` to a block which will be evaluated if no Nushell completions were found.
141141
You can configure the block to run an external completer, such as [carapace](https://github.com/rsteube/carapace-bin).
142142
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+
143156
This example should enable carapace external completions:
144157
145158
```nu
146-
# config.nu
147159
let carapace_completer = {|spans|
148160
carapace $spans.0 nushell $spans | from json
149161
}
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-
}
162162
```
163163
164164
Multiple completers can be defined as such:
165165

166166
```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}
173173
}
174174
```
175175

176176
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.)
177177

178178
```nu
179179
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 }
184+
| flatten
192185
}
193186
```
194187

0 commit comments

Comments
 (0)