Wrap nushell integration script in a module

This prevents the completion command "nu-complete __zoxide_z" from
polluting the command namespace.
This commit is contained in:
Juhan280 2026-02-12 17:08:30 +06:00
parent 32ed3ec28a
commit bdedc2a813
1 changed files with 121 additions and 112 deletions

View File

@ -1,21 +1,23 @@
{%- let section = "# =============================================================================\n#" -%} {%- let section = "# =============================================================================" -%}
{%- let not_configured = "# -- not configured --" -%} {%- let not_configured = "# -- not configured --" -%}
# Code generated by zoxide. DO NOT EDIT. # Code generated by zoxide. DO NOT EDIT.
const homedir = if $nu.home-dir? != null { $nu.home-dir } else { $nu.home-path } module zoxide_integration {
const homedir = if $nu.home-dir? != null { $nu.home-dir } else { $nu.home-path }
{{ section }} {{ section }}
# Hook configuration for zoxide. #
# # Hook configuration for zoxide.
#
{% if hook == InitHook::None -%} {% if hook == InitHook::None -%}
{{ not_configured }} {{ not_configured }}
{%- else -%} {%- else -%}
# Initialize hook to add new entries to the database. # Initialize hook to add new entries to the database.
export-env { export-env {
{%- if hook == InitHook::Prompt %} {%- if hook == InitHook::Prompt %}
$env.config = ( $env.config = (
$env.config? $env.config?
| default {} | default {}
@ -31,7 +33,7 @@ export-env {
code: {|| ^zoxide add -- $env.PWD} code: {|| ^zoxide add -- $env.PWD}
}) })
} }
{%- else if hook == InitHook::Pwd %} {%- else if hook == InitHook::Pwd %}
$env.config = ( $env.config = (
$env.config? $env.config?
| default {} | default {}
@ -48,16 +50,17 @@ export-env {
code: {|_, dir| ^zoxide add -- $dir} code: {|_, dir| ^zoxide add -- $dir}
}) })
} }
{%- endif %} {%- endif %}
} }
{%- endif %} {%- endif %}
{{ section }} {{ section }}
# Completion for __zoxide_z #
# # Completion for __zoxide_z
#
def "nu-complete __zoxide_z" [context: string] { def "nu-complete __zoxide_z" [context: string] {
let ast = ast --flatten $context | skip 1 let ast = ast --flatten $context | skip 1
# If the user has typed a space after the first argument, use the custom # If the user has typed a space after the first argument, use the custom
@ -81,14 +84,15 @@ def "nu-complete __zoxide_z" [context: string] {
} }
completions: $completions, completions: $completions,
} }
} }
{{ section }} {{ section }}
# When using zoxide with --no-cmd, alias these internal functions as desired. #
# # When using zoxide with --no-cmd, alias these internal functions as desired.
#
# Jump to a directory using only keywords. # Jump to a directory using only keywords.
export def --env --wrapped __zoxide_z [...rest: directory@"nu-complete __zoxide_z"] { export def --env --wrapped __zoxide_z [...rest: directory@"nu-complete __zoxide_z"] {
let path = match $rest { let path = match $rest {
[] => {'~'}, [] => {'~'},
[ '-' ] => {'-'}, [ '-' ] => {'-'},
@ -98,36 +102,41 @@ export def --env --wrapped __zoxide_z [...rest: directory@"nu-complete __zoxide_
} }
} }
cd $path cd $path
{%- if echo %} {%- if echo %}
echo $env.PWD echo $env.PWD
{%- endif %} {%- endif %}
} }
# Jump to a directory using interactive search. # Jump to a directory using interactive search.
export 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")' cd $'(^zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
{%- if echo %} {%- if echo %}
echo $env.PWD echo $env.PWD
{%- endif %} {%- 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 %}
} }
export use zoxide_integration *
{{ section }} {{ 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): # Add this to your env file (find it by running `$nu.env-path` in Nushell):
# #
# zoxide init nushell | save -f ~/.zoxide.nu # zoxide init nushell | save -f ~/.zoxide.nu