2021-04-08 18:35:42 +00:00
|
|
|
{%- let section = "# =============================================================================\n#" -%}
|
|
|
|
{%- let not_configured = "# -- not configured --" -%}
|
2021-03-31 16:45:43 +00:00
|
|
|
|
2021-08-05 08:52:12 +00:00
|
|
|
# Code generated by zoxide. DO NOT EDIT.
|
|
|
|
|
2021-04-08 18:35:42 +00:00
|
|
|
{{ section }}
|
2021-03-31 16:45:43 +00:00
|
|
|
# Hook configuration for zoxide.
|
|
|
|
#
|
2022-04-22 07:41:11 +00:00
|
|
|
{% match hook %}
|
2021-05-03 21:12:43 +00:00
|
|
|
{%- when InitHook::None %}
|
2021-08-31 10:59:57 +00:00
|
|
|
{{ not_configured }}
|
2021-03-31 16:45:43 +00:00
|
|
|
|
2021-05-03 21:12:43 +00:00
|
|
|
{%- when InitHook::Prompt %}
|
2022-04-22 07:41:11 +00:00
|
|
|
# Default prompt for Nushell.
|
|
|
|
let-env __zoxide_oldprompt = (if '__zoxide_oldprompt' in (env).name {
|
|
|
|
$env.__zoxide_oldprompt
|
|
|
|
} else if 'PROMPT_COMMAND' in (env).name {
|
|
|
|
$env.PROMPT_COMMAND
|
|
|
|
} else {
|
|
|
|
{ $env.PWD }
|
|
|
|
})
|
|
|
|
|
|
|
|
# Hook to add new entries to the database.
|
2021-03-31 16:45:43 +00:00
|
|
|
def __zoxide_hook [] {
|
2022-04-22 07:41:11 +00:00
|
|
|
zoxide add -- $env.PWD
|
2021-03-31 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 10:59:57 +00:00
|
|
|
# Initialize hook.
|
2022-04-22 07:41:11 +00:00
|
|
|
let-env PROMPT_COMMAND = {
|
|
|
|
__zoxide_hook
|
|
|
|
do $env.__zoxide_oldprompt
|
|
|
|
}
|
2021-08-31 10:59:57 +00:00
|
|
|
|
2021-05-03 21:12:43 +00:00
|
|
|
{%- when InitHook::Pwd %}
|
2022-04-22 07:41:11 +00:00
|
|
|
echo "zoxide: PWD hooks are not supported on Nushell.\nUse `zoxide init nushell --hook prompt` instead."
|
|
|
|
|
2021-03-31 16:45:43 +00:00
|
|
|
{%- endmatch %}
|
|
|
|
|
2021-04-08 18:35:42 +00:00
|
|
|
{{ section }}
|
2022-04-22 07:41:11 +00:00
|
|
|
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
2021-03-31 16:45:43 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
# Jump to a directory using only keywords.
|
2022-04-22 07:41:11 +00:00
|
|
|
def-env __zoxide_z [...rest:string] {
|
|
|
|
# `z -` does not work yet, see https://github.com/nushell/nushell/issues/4769
|
|
|
|
let arg0 = ($rest | append '~').0
|
2022-08-12 07:13:41 +00:00
|
|
|
let path = if (($rest | length) <= 1) && ($arg0 == '-' || ($arg0 | path expand | path type) == dir) {
|
2022-04-22 07:41:11 +00:00
|
|
|
$arg0
|
|
|
|
} else {
|
|
|
|
(zoxide query --exclude $env.PWD -- $rest | str trim -r -c "\n")
|
|
|
|
}
|
|
|
|
cd $path
|
2021-05-05 23:01:57 +00:00
|
|
|
{%- if echo %}
|
2022-04-22 07:41:11 +00:00
|
|
|
echo $env.PWD
|
2021-05-05 23:01:57 +00:00
|
|
|
{%- endif %}
|
2021-03-31 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Jump to a directory using interactive search.
|
2022-04-22 07:41:11 +00:00
|
|
|
def-env __zoxide_zi [...rest:string] {
|
|
|
|
cd $'(zoxide query -i -- $rest | str trim -r -c "\n")'
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- if echo %}
|
2022-04-22 07:41:11 +00:00
|
|
|
echo $env.PWD
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- endif %}
|
2021-03-31 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2021-04-08 18:35:42 +00:00
|
|
|
{{ section }}
|
2022-04-10 22:11:51 +00:00
|
|
|
# Commands for zoxide. Disable these using --no-cmd.
|
2021-03-31 16:45:43 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
{%- match cmd %}
|
|
|
|
{%- when Some with (cmd) %}
|
|
|
|
|
2021-06-02 21:19:21 +00:00
|
|
|
alias {{cmd}} = __zoxide_z
|
|
|
|
alias {{cmd}}i = __zoxide_zi
|
2021-03-31 16:45:43 +00:00
|
|
|
|
|
|
|
{%- when None %}
|
2021-04-08 18:35:42 +00:00
|
|
|
|
|
|
|
{{ not_configured }}
|
2021-03-31 16:45:43 +00:00
|
|
|
|
|
|
|
{%- endmatch %}
|
|
|
|
|
2021-04-08 18:35:42 +00:00
|
|
|
{{ section }}
|
2022-04-22 07:41:11 +00:00
|
|
|
# Add this to your env file (find it by running `$nu.env-path` in Nushell):
|
|
|
|
#
|
|
|
|
# zoxide init nushell --hook prompt | save ~/.zoxide.nu
|
|
|
|
#
|
|
|
|
# Now, add this to the end of your config file (find it by running
|
|
|
|
# `$nu.config-path` in Nushell):
|
2021-04-27 12:07:38 +00:00
|
|
|
#
|
2022-04-22 07:41:11 +00:00
|
|
|
# source ~/.zoxide.nu
|
2021-04-27 12:07:38 +00:00
|
|
|
#
|
2022-08-12 07:13:41 +00:00
|
|
|
# Note: zoxide only supports Nushell v0.62.0 and above.
|