Add nushell completion for __zoxide_z
This commit is contained in:
parent
fcce9804a7
commit
32ed3ec28a
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
# Code generated by zoxide. DO NOT EDIT.
|
||||
|
||||
const homedir = if $nu.home-dir? != null { $nu.home-dir } else { $nu.home-path }
|
||||
|
||||
{{ section }}
|
||||
# Hook configuration for zoxide.
|
||||
#
|
||||
|
|
@ -51,12 +53,42 @@ export-env {
|
|||
|
||||
{%- endif %}
|
||||
|
||||
{{ section }}
|
||||
# Completion for __zoxide_z
|
||||
#
|
||||
|
||||
def "nu-complete __zoxide_z" [context: string] {
|
||||
let ast = ast --flatten $context | skip 1
|
||||
|
||||
# If the user has typed a space after the first argument, use the custom
|
||||
# completer. If not, use the built-in directory completion.
|
||||
if ($ast | is-empty) { return null }
|
||||
if $ast.0.span.end >= ($context | str length) { return null }
|
||||
|
||||
let completions = ^zoxide query --exclude $env.PWD --list -- ...$ast.content
|
||||
| lines | each {
|
||||
if $in starts-with $"($homedir)(char psep)" {
|
||||
str replace $homedir "~"
|
||||
} else {}
|
||||
} | wrap value
|
||||
| insert span { start: ($ast | first).span.start, end: ($ast | last).span.end }
|
||||
|
||||
{
|
||||
options: {
|
||||
sort: false,
|
||||
case_sensitive: false,
|
||||
completion_algorithm: "substring",
|
||||
}
|
||||
completions: $completions,
|
||||
}
|
||||
}
|
||||
|
||||
{{ section }}
|
||||
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
||||
#
|
||||
|
||||
# Jump to a directory using only keywords.
|
||||
def --env --wrapped __zoxide_z [...rest: string] {
|
||||
export def --env --wrapped __zoxide_z [...rest: directory@"nu-complete __zoxide_z"] {
|
||||
let path = match $rest {
|
||||
[] => {'~'},
|
||||
[ '-' ] => {'-'},
|
||||
|
|
@ -72,7 +104,7 @@ def --env --wrapped __zoxide_z [...rest: string] {
|
|||
}
|
||||
|
||||
# Jump to a directory using interactive search.
|
||||
def --env --wrapped __zoxide_zi [...rest:string] {
|
||||
export def --env --wrapped __zoxide_zi [...rest: string] {
|
||||
cd $'(^zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
|
||||
{%- if echo %}
|
||||
echo $env.PWD
|
||||
|
|
@ -86,8 +118,8 @@ def --env --wrapped __zoxide_zi [...rest:string] {
|
|||
{%- match cmd %}
|
||||
{%- when Some with (cmd) %}
|
||||
|
||||
alias {{cmd}} = __zoxide_z
|
||||
alias {{cmd}}i = __zoxide_zi
|
||||
export alias {{cmd}} = __zoxide_z
|
||||
export alias {{cmd}}i = __zoxide_zi
|
||||
|
||||
{%- when None %}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue