fix: nushell completions

This commit is contained in:
Youwen Wu 2025-04-16 12:13:56 -07:00
parent 11a7673570
commit 775fc350f7
Signed by: youwen
GPG key ID: 865658ED1FE61EC3
2 changed files with 55 additions and 39 deletions

View file

@ -1,12 +1,13 @@
let fish_completer = {|spans|
fish --command $'complete "--do-complete=($spans | str join " ")"'
| from tsv --flexible --noheaders --no-infer
| rename value description
| update value {
if ($in | path exists) {$'"($in | str replace "\"" "\\\"" )"'} else {$in}
fish --command $'complete --escape "--do-complete=($spans | str join " ")"'
| $"value(char tab)description(char newline)" + $in
| from tsv --flexible --no-infer
| each {|i|
if '\' in $i.value {
$i | merge {'value': $"\"($i.value | str replace -a '\' '')\""}
} else {$i}
}
}
# This completer will use fish by default
let external_completer = {|spans|
let expanded_alias = scope aliases
@ -28,20 +29,3 @@ let external_completer = {|spans|
}
$env.config.completions.external.completer = $external_completer
def "nu-complete zoxide path" [context: string] {
let parts = $context | split row " " | skip 1
{
options: {
sort: false
completion_algorithm: prefix
positional: false
case_sensitive: false
}
completions: (zoxide query --list --exclude $env.PWD -- ...$parts | lines)
}
}
def --env --wrapped z [...rest: string@"nu-complete zoxide path"] {
__zoxide_z ...$rest
}