Provide completions for Nushell

This commit is contained in:
ysthakur 2025-04-24 15:11:48 -04:00
parent ee8bbe57d3
commit df52401611
No known key found for this signature in database
1 changed files with 53 additions and 19 deletions

View File

@ -55,8 +55,39 @@ export-env {
# When using zoxide with --no-cmd, alias these internal functions as desired. # When using zoxide with --no-cmd, alias these internal functions as desired.
# #
# For hiding the "nu-complete zoxide path" command
module zoxide-commands {
def "nu-complete zoxide path" [context: string] {
let parts = $context | str trim | split row " " | skip 1 | each { str downcase }
let completions = (
zoxide query --list --exclude $env.PWD -- ...$parts
| lines
| each { |dir|
if ($parts | length) <= 1 {
$dir
} else {
let dir_lower = $dir | str downcase
let rem_start = $parts | drop 1 | reduce --fold 0 { |part, rem_start|
($dir_lower | str index-of --range $rem_start.. $part) + ($part | str length)
}
{
value: ($dir | str substring $rem_start..),
description: $dir
}
}
})
{
options: {
sort: false,
completion_algorithm: substring,
case_sensitive: false,
},
completions: $completions,
}
}
# Jump to a directory using only keywords. # Jump to a directory using only keywords.
def --env --wrapped __zoxide_z [...rest: string] { export def --env --wrapped __zoxide_z [...rest: string@"nu-complete zoxide path"] {
let path = match $rest { let path = match $rest {
[] => {'~'}, [] => {'~'},
[ '-' ] => {'-'}, [ '-' ] => {'-'},
@ -72,12 +103,15 @@ def --env --wrapped __zoxide_z [...rest: string] {
} }
# Jump to a directory using interactive search. # Jump to a directory using interactive search.
def --env --wrapped __zoxide_zi [...rest:string] { export def --env --wrapped __zoxide_zi [...rest:string@"nu-complete zoxide path"] {
cd $'(zoxide query --interactive -- ...$rest | str trim -r -c "\n")' cd $'(zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
{%- if echo %} {%- if echo %}
echo $env.PWD echo $env.PWD
{%- endif %} {%- endif %}
} }
}
use zoxide-commands *
{{ section }} {{ section }}
# Commands for zoxide. Disable these using --no-cmd. # Commands for zoxide. Disable these using --no-cmd.