Merge 59155c8ee0 into c8a47a068b
This commit is contained in:
commit
edea0650c9
|
|
@ -270,7 +270,7 @@ zoxide can be installed in 4 easy steps:
|
||||||
> ```
|
> ```
|
||||||
>
|
>
|
||||||
> **Note:**
|
> **Note:**
|
||||||
> zoxide only supports Nushell v0.89.0+.
|
> zoxide only supports Nushell v0.106.0+.
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,101 +1,134 @@
|
||||||
{%- 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.
|
||||||
|
|
||||||
{{ section }}
|
module zoxide_integration {
|
||||||
# Hook configuration for zoxide.
|
# From version 0.110.0, $nu.home-path has been renamed to $nu.home-dir
|
||||||
#
|
const homedir = if $nu.home-dir? != null { $nu.home-dir } else { $nu.home-path }
|
||||||
|
|
||||||
{% if hook == InitHook::None -%}
|
{{ section }}
|
||||||
{{ not_configured }}
|
#
|
||||||
|
# Hook configuration for zoxide.
|
||||||
|
#
|
||||||
|
|
||||||
{%- else -%}
|
{% if hook == InitHook::None -%}
|
||||||
# Initialize hook to add new entries to the database.
|
{{ not_configured }}
|
||||||
export-env {
|
|
||||||
{%- if hook == InitHook::Prompt %}
|
{%- else -%}
|
||||||
$env.config = (
|
# Initialize hook to add new entries to the database.
|
||||||
$env.config?
|
export-env {
|
||||||
| default {}
|
{%- if hook == InitHook::Prompt %}
|
||||||
| upsert hooks { default {} }
|
let __zoxide_hooked = (
|
||||||
| upsert hooks.pre_prompt { default [] }
|
$env.config.hooks.pre_prompt
|
||||||
)
|
| any { get __zoxide_hook? | default false }
|
||||||
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 {
|
||||||
if not $__zoxide_hooked {
|
__zoxide_hook: true,
|
||||||
$env.config.hooks.pre_prompt = ($env.config.hooks.pre_prompt | append {
|
code: {|| ^zoxide add -- $env.PWD}
|
||||||
__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 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 %}
|
||||||
|
|
||||||
{{ section }}
|
{{ section }}
|
||||||
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
#
|
||||||
#
|
# Completion for __zoxide_z
|
||||||
|
#
|
||||||
|
|
||||||
# Jump to a directory using only keywords.
|
def "nu-complete __zoxide_z" [context: string] {
|
||||||
def --env --wrapped __zoxide_z [...rest: string] {
|
let ast = ast --flatten $context | skip 1
|
||||||
let path = match $rest {
|
|
||||||
[] => {'~'},
|
# If the user has typed a space after the first argument, use the custom
|
||||||
[ '-' ] => {'-'},
|
# completer. If not, use the built-in directory completion.
|
||||||
[ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg}
|
if ($ast | is-empty) { return null }
|
||||||
_ => {
|
if $ast.0.span.end >= ($context | str length) { return null }
|
||||||
^zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n"
|
|
||||||
|
let completions = ^zoxide query --exclude $env.PWD --list -- ...$ast.content
|
||||||
|
| lines | each {
|
||||||
|
if $in starts-with $"($homedir)(char psep)" {
|
||||||
|
str replace $homedir "~"
|
||||||
|
} else {}
|
||||||
|
} | wrap display_override
|
||||||
|
| insert value { get display_override | debug --raw-value }
|
||||||
|
| insert span { start: ($ast | first).span.start, end: ($ast | last).span.end }
|
||||||
|
|
||||||
|
{
|
||||||
|
options: {
|
||||||
|
sort: false,
|
||||||
|
filter: false,
|
||||||
|
case_sensitive: false,
|
||||||
|
completion_algorithm: "substring",
|
||||||
|
}
|
||||||
|
completions: $completions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cd $path
|
|
||||||
{%- if echo %}
|
{{ section }}
|
||||||
echo $env.PWD
|
#
|
||||||
{%- endif %}
|
# 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 {
|
||||||
|
[] => {'~'},
|
||||||
|
[ '-' ] => {'-'},
|
||||||
|
[ $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 %}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{ 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 %}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Jump to a directory using interactive search.
|
export use zoxide_integration *
|
||||||
def --env --wrapped __zoxide_zi [...rest:string] {
|
|
||||||
cd $'(^zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
|
|
||||||
{%- if echo %}
|
|
||||||
echo $env.PWD
|
|
||||||
{%- endif %}
|
|
||||||
}
|
|
||||||
|
|
||||||
{{ section }}
|
{{ section }}
|
||||||
# Commands for zoxide. Disable these using --no-cmd.
|
|
||||||
#
|
#
|
||||||
|
|
||||||
{%- match cmd %}
|
|
||||||
{%- when Some with (cmd) %}
|
|
||||||
|
|
||||||
alias {{cmd}} = __zoxide_z
|
|
||||||
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
|
||||||
|
|
@ -105,4 +138,4 @@ alias {{cmd}}i = __zoxide_zi
|
||||||
#
|
#
|
||||||
# source ~/.zoxide.nu
|
# source ~/.zoxide.nu
|
||||||
#
|
#
|
||||||
# Note: zoxide only supports Nushell v0.89.0+.
|
# Note: zoxide only supports Nushell v0.106.0+.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue