zoxide/templates/nushell.txt

93 lines
2.1 KiB
Plaintext
Raw Normal View History

2021-04-09 00:05:42 +05:30
{%- let section = "# =============================================================================\n#" -%}
{%- let not_configured = "# -- not configured --" -%}
2021-03-31 22:15:43 +05:30
2021-08-05 14:22:12 +05:30
# Code generated by zoxide. DO NOT EDIT.
2021-04-09 00:05:42 +05:30
{{ section }}
2021-03-31 22:15:43 +05:30
# Hook configuration for zoxide.
#
2022-04-22 13:11:11 +05:30
{% match hook %}
2021-05-04 02:42:43 +05:30
{%- when InitHook::None %}
2021-08-31 16:29:57 +05:30
{{ not_configured }}
2021-03-31 22:15:43 +05:30
2021-05-04 02:42:43 +05:30
{%- when InitHook::Prompt %}
2022-04-22 13:11:11 +05:30
# 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 22:15:43 +05:30
def __zoxide_hook [] {
2022-04-22 13:11:11 +05:30
zoxide add -- $env.PWD
2021-03-31 22:15:43 +05:30
}
2021-08-31 16:29:57 +05:30
# Initialize hook.
2022-04-22 13:11:11 +05:30
let-env PROMPT_COMMAND = {
__zoxide_hook
do $env.__zoxide_oldprompt
}
2021-08-31 16:29:57 +05:30
2021-05-04 02:42:43 +05:30
{%- when InitHook::Pwd %}
2022-04-22 13:11:11 +05:30
echo "zoxide: PWD hooks are not supported on Nushell.\nUse `zoxide init nushell --hook prompt` instead."
2021-03-31 22:15:43 +05:30
{%- endmatch %}
2021-04-09 00:05:42 +05:30
{{ section }}
2022-04-22 13:11:11 +05:30
# When using zoxide with --no-cmd, alias these internal functions as desired.
2021-03-31 22:15:43 +05:30
#
# Jump to a directory using only keywords.
2022-04-22 13:11:11 +05:30
def-env __zoxide_z [...rest:string] {
# `z -` does not work yet, see https://github.com/nushell/nushell/issues/4769
let arg0 = ($rest | append '~').0
let path = if ($rest | length) <= 1 && ($arg0 | path expand | path type) == dir {
$arg0
} else {
(zoxide query --exclude $env.PWD -- $rest | str trim -r -c "\n")
}
cd $path
2021-05-06 04:31:57 +05:30
{%- if echo %}
2022-04-22 13:11:11 +05:30
echo $env.PWD
2021-05-06 04:31:57 +05:30
{%- endif %}
2021-03-31 22:15:43 +05:30
}
# Jump to a directory using interactive search.
2022-04-22 13:11:11 +05:30
def-env __zoxide_zi [...rest:string] {
cd $'(zoxide query -i -- $rest | str trim -r -c "\n")'
2021-04-09 00:05:42 +05:30
{%- if echo %}
2022-04-22 13:11:11 +05:30
echo $env.PWD
2021-04-09 00:05:42 +05:30
{%- endif %}
2021-03-31 22:15:43 +05:30
}
2021-04-09 00:05:42 +05:30
{{ section }}
2022-04-11 03:41:51 +05:30
# Commands for zoxide. Disable these using --no-cmd.
2021-03-31 22:15:43 +05:30
#
{%- match cmd %}
{%- when Some with (cmd) %}
2021-06-03 02:49:21 +05:30
alias {{cmd}} = __zoxide_z
alias {{cmd}}i = __zoxide_zi
2021-03-31 22:15:43 +05:30
{%- when None %}
2021-04-09 00:05:42 +05:30
{{ not_configured }}
2021-03-31 22:15:43 +05:30
{%- endmatch %}
2021-04-09 00:05:42 +05:30
{{ section }}
2022-04-22 13:11:11 +05:30
# 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 17:37:38 +05:30
#
2022-04-22 13:11:11 +05:30
# source ~/.zoxide.nu
2021-04-27 17:37:38 +05:30
#
2022-04-22 13:11:11 +05:30
# Note: zoxide only supports Nushell v0.61.0 and above.