nushell: escape external completions

This commit is contained in:
LordMZTE 2024-07-14 19:07:29 +02:00
parent b575bebe13
commit 1926aaf83e
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6

View file

@ -1,8 +1,14 @@
# See: https://www.nushell.sh/cookbook/external_completers.html#fish-completer
let fish_completer = {|spans|
let completer = {|spans|
fish --command $'complete "--do-complete=($spans | str join " ")"'
| $"value(char tab)description(char newline)" + $in
| from tsv --flexible --no-infer
| each { |comp|
let escaped = $comp.value | str replace --all '"' '\"'
{
value: (if ($escaped | str contains " ") { $'"($escaped)"' } else { $escaped })
description: $comp.description
}
}
}
$env.config = {
@ -15,9 +21,10 @@ $env.config = {
}
completions: {
algorithm: "fuzzy"
external: (if (which fish | is-not-empty) { {
enable: true
completer: $fish_completer
completer: $completer
} } else { {} })
}