Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 107 additions & 77 deletions templates/nushell.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,97 +3,127 @@

# Code generated by zoxide. DO NOT EDIT.

{{ section }}
# Hook configuration for zoxide.
#
module zoxide_integration {

{% if hook == InitHook::None -%}
{{ not_configured }}

{%- else -%}
# Initialize hook to add new entries to the database.
export-env {
{%- if hook == InitHook::Prompt %}
$env.config = (
$env.config?
| default {}
| upsert hooks { default {} }
| upsert hooks.pre_prompt { default [] }
)
let __zoxide_hooked = (
$env.config.hooks.pre_prompt | any { try { get __zoxide_hook } catch { 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 %}
$env.config = (
$env.config?
| default {}
| upsert hooks { default {} }
| upsert hooks.env_change { default {} }
| upsert hooks.env_change.PWD { default [] }
)
let __zoxide_hooked = (
$env.config.hooks.env_change.PWD | any { try { get __zoxide_hook } catch { 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 }}
# Hook configuration for zoxide.
#

{% if hook == InitHook::None -%}
{{ not_configured }}

{%- else -%}
# Initialize hook to add new entries to the database.
export-env {
{%- if hook == InitHook::Prompt %}
$env.config = (
$env.config?
| default {}
| upsert hooks { default {} }
| upsert hooks.pre_prompt { default [] }
)
let __zoxide_hooked = (
$env.config.hooks.pre_prompt | any { try { get __zoxide_hook } catch { 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 %}
$env.config = (
$env.config?
| default {}
| upsert hooks { default {} }
| upsert hooks.env_change { default {} }
| upsert hooks.env_change.PWD { default [] }
)
let __zoxide_hooked = (
$env.config.hooks.env_change.PWD | any { try { get __zoxide_hook } catch { 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 %}
}
{%- endif %}
}

{%- endif %}
{%- endif %}

{{ section }}
# When using zoxide with --no-cmd, alias these internal functions as desired.
#
{{ 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 }

# Jump to a directory using only keywords.
def --env --wrapped __zoxide_z [...rest: string] {
let path = match $rest {
[] => {'~'},
[ '-' ] => {'-'},
[ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg}
_ => {
^zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n"
let completions = ^zoxide query --exclude $env.PWD --list -- ...$ast.content
| lines | first 10 | wrap value
| insert span { start: ($ast | first).span.start, end: ($ast | last).span.end }

{
options: {
sort: false,
completion_algorithm: "fuzzy",
}
completions: $completions,
}
}
cd $path
{%- if echo %}
echo $env.PWD
{%- endif %}
}

# Jump to a directory using interactive search.
def --env --wrapped __zoxide_zi [...rest:string] {
cd $'(^zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
{%- if echo %}
echo $env.PWD
{%- endif %}
}
{{ section }}
# When using zoxide with --no-cmd, alias these internal functions as desired.
#

{{ section }}
# Commands for zoxide. Disable these using --no-cmd.
#
# Jump to a directory using only keywords.
export def --env --wrapped __zoxide_z [...rest: directory@"nu-complete __zoxide_z"] {
let path = match $rest {
[] => {'~'},
[ '-' ] => {'-'},
[ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg}
_ => {
^zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n"
}
}
cd $path
{%- 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 %}
}

{%- match cmd %}
{%- when Some with (cmd) %}
{{ section }}
# Commands for zoxide. Disable these using --no-cmd.
#

alias {{cmd}} = __zoxide_z
alias {{cmd}}i = __zoxide_zi
{%- match cmd %}
{%- when Some with (cmd) %}

{%- when None %}
export alias {{cmd}} = __zoxide_z
export alias {{cmd}}i = __zoxide_zi

{{ not_configured }}
{%- when None %}

{{ not_configured }}

{%- endmatch %}
}

{%- endmatch %}
export use zoxide_integration *

{{ section }}
# Add this to your env file (find it by running `$nu.env-path` in Nushell):
Expand Down
Loading