unwrap module

This commit is contained in:
Juhan280 2026-07-14 18:40:18 +06:00
parent 4fa24fc5e5
commit e846019923
1 changed files with 94 additions and 103 deletions

View File

@ -1,119 +1,110 @@
{%- let section = "# =============================================================================" -%}
{%- let section = "# =============================================================================\n#" -%}
{%- let not_configured = "# -- not configured --" -%}
# Code generated by zoxide. DO NOT EDIT.
module zoxide_integration {
{{ section }}
#
# Hook configuration for zoxide.
#
{{ section }}
# Hook configuration for zoxide.
#
{% if hook == InitHook::None -%}
{{ not_configured }}
{% if hook == InitHook::None -%}
{{ not_configured }}
{%- else -%}
# Initialize hook to add new entries to the database.
export-env {
{%- if hook == InitHook::Prompt %}
let __zoxide_hooked = (
$env.config.hooks.pre_prompt
| any { get __zoxide_hook? | default false }
)
if not $__zoxide_hooked {
$env.config.hooks.pre_prompt = ($env.config.hooks.pre_prompt | append {
__zoxide_hook: true,
code: {|| ^zoxide add -- $env.PWD}
})
}
{%- else if hook == InitHook::Pwd %}
let __zoxide_hooked = (
$env.config.hooks.env_change.PWD? | default []
| any { get __zoxide_hook? | default false }
)
if not $__zoxide_hooked {
$env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD? | append {
__zoxide_hook: true,
code: {|_, dir| ^zoxide add -- $dir}
})
}
{%- endif %}
{%- else -%}
# Initialize hook to add new entries to the database.
export-env {
{%- if hook == InitHook::Prompt %}
let __zoxide_hooked = (
$env.config.hooks.pre_prompt
| any { get __zoxide_hook? | default false }
)
if not $__zoxide_hooked {
$env.config.hooks.pre_prompt = ($env.config.hooks.pre_prompt | append {
__zoxide_hook: true,
code: {|| ^zoxide add -- $env.PWD}
})
}
{%- endif %}
{{ section }}
#
# Completion for __zoxide_z
#
def "nu-complete __zoxide_z" [context: string] {
let ast = ast --flatten $context | skip 1 # skip the command name
# 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 }
^zoxide query --exclude $env.PWD --interactive -- ...$ast.content
| if $in starts-with $"($nu.home-dir)(char psep)" { str replace $nu.home-dir "~" } else {}
| [{
display_override: $in,
value: ($in | debug --raw-value),
span: { start: ($ast | first).span.start, end: ($ast | last).span.end }
}]
{%- else if hook == InitHook::Pwd %}
let __zoxide_hooked = (
$env.config.hooks.env_change.PWD? | default []
| any { get __zoxide_hook? | default false }
)
if not $__zoxide_hooked {
$env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD? | append {
__zoxide_hook: true,
code: {|_, dir| ^zoxide add -- $dir}
})
}
{{ section }}
#
# When using zoxide with --no-cmd, alias these internal functions as desired.
#
# Jump to a directory using only keywords.
export def --env --wrapped __zoxide_z [...rest: directory@"nu-complete __zoxide_z"] {
let path = match $rest {
[] => { cd ~ },
[ '-' ] => { cd - },
[ $arg ] if (try { cd $arg; true } catch { false }) => {},
_ => {
cd (^zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n")
}
}
{%- if echo %}
echo $env.PWD
{%- endif %}
}
# Jump to a directory using interactive search.
export def --env --wrapped __zoxide_zi [...rest: string] {
cd $'(^zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
{%- if echo %}
echo $env.PWD
{%- endif %}
}
{{ section }}
#
# Commands for zoxide. Disable these using --no-cmd.
#
{%- match cmd %}
{%- when Some with (cmd) %}
export alias {{cmd}} = __zoxide_z
export alias {{cmd}}i = __zoxide_zi
{%- when None %}
{{ not_configured }}
{%- endmatch %}
{%- endif %}
}
export use zoxide_integration *
{%- endif %}
{{ section }}
# Completion for __zoxide_z
#
def "nu-complete __zoxide_z" [context: string] {
let ast = ast --flatten $context | skip 1 # skip the command name
# 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 }
^zoxide query --exclude $env.PWD --interactive -- ...$ast.content
| if $in starts-with $"($nu.home-dir)(char psep)" { str replace $nu.home-dir "~" } else {}
| [{
display_override: $in,
value: ($in | debug --raw-value),
span: { start: ($ast | first).span.start, end: ($ast | last).span.end }
}]
}
{{ section }}
# When using zoxide with --no-cmd, alias these internal functions as desired.
#
# Jump to a directory using only keywords.
export def --env --wrapped __zoxide_z [...rest: directory@"nu-complete __zoxide_z"] {
match $rest {
[] => { cd ~ },
[ '-' ] => { cd - },
[ $arg ] if (try { cd $arg; true } catch { false }) => {},
_ => {
cd (^zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n")
}
}
{%- if echo %}
echo $env.PWD
{%- endif %}
}
# Jump to a directory using interactive search.
export def --env --wrapped __zoxide_zi [...rest: string] {
cd $'(^zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
{%- if echo %}
echo $env.PWD
{%- endif %}
}
{{ section }}
# Commands for zoxide. Disable these using --no-cmd.
#
{%- match cmd %}
{%- when Some with (cmd) %}
export alias {{cmd}} = __zoxide_z
export alias {{cmd}}i = __zoxide_zi
{%- when None %}
{{ not_configured }}
{%- endmatch %}
{{ section }}
# Add this to your env file (find it by running `$nu.env-path` in Nushell):
#
# zoxide init nushell | save -f ~/.zoxide.nu