Skip to content

Commit

Permalink
Fix custom completion scripts (nushell#959)
Browse files Browse the repository at this point in the history
* Fix fish completer returning empty string

* Fix completer override with fallback example

* Fix fish completer edge cases

Wgeb the first element of the completion list doesn't have a
description, `from tsv` throws an error. When using the `--flexible`
flag, the second column disappears.

This solution adds headers to the text, that way we'll get the two
columns. As a bonus, we avoid having to rename the columns :)
  • Loading branch information
JoaquinTrinanes committed Jun 27, 2023
1 parent 4cdc1bd commit 53e4128
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions book/custom_completions.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,9 @@ Multiple completers can be defined as such:
```nu
let multiple_completers = {|spans|
{
$spans.0: { default_completer $spans | from json } # default
ls: { ls_completer $spans | from json }
git: { git_completer $spans | from json }
} | each {|it| do $it}
ls: $ls_completer
git: $git_completer
} | get -i $spans.0 | default $default_completer | do $in $spans
}
```

Expand All @@ -178,10 +177,8 @@ This example shows an external completer that uses the `fish` shell's `complete`
```nu
let fish_completer = {|spans|
fish --command $'complete "--do-complete=($spans | str join " ")"'
| str trim
| split row "\n"
| each { |line| $line | split column "\t" value description }
| flatten
| $"value(char tab)description(char newline)" + $in
| from tsv --flexible --no-infer
}
```

Expand Down

0 comments on commit 53e4128

Please sign in to comment.