zoxide/templates/nushell.txt

90 lines
2.5 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-08-13 02:02:43 +05:30
{% if hook == InitHook::None -%}
{{ not_configured }}
2022-04-22 13:11:11 +05:30
2022-08-13 02:02:43 +05:30
{%- else -%}
# Initialize hook to add new entries to the database.
2023-01-07 22:58:10 +05:30
if (not ($env | default false __zoxide_hooked | get __zoxide_hooked)) {
$env.__zoxide_hooked = true
2022-08-13 02:02:43 +05:30
{%- if hook == InitHook::Prompt %}
$env.config = ($env | default {} config).config
$env.config = ($env.config | default {} hooks)
$env.config = ($env.config | update hooks ($env.config.hooks | default [] pre_prompt))
$env.config = ($env.config | update hooks.pre_prompt ($env.config.hooks.pre_prompt | append { ||
2023-01-07 22:58:10 +05:30
zoxide add -- $env.PWD
}))
2022-08-13 02:02:43 +05:30
{%- else if hook == InitHook::Pwd %}
$env.config = ($env | default {} config).config
$env.config = ($env.config | default {} hooks)
$env.config = ($env.config | update hooks ($env.config.hooks | default {} env_change))
$env.config = ($env.config | update hooks.env_change ($env.config.hooks.env_change | default [] PWD))
$env.config = ($env.config | update hooks.env_change.PWD ($env.config.hooks.env_change.PWD | append {|_, dir|
2023-01-07 22:58:10 +05:30
zoxide add -- $dir
}))
2022-08-13 02:02:43 +05:30
{%- endif %}
2023-01-07 22:58:10 +05:30
}
2022-04-22 13:11:11 +05:30
2022-08-13 02:02:43 +05:30
{%- endif %}
2021-03-31 22:15:43 +05:30
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.
def --env __zoxide_z [...rest:string] {
2022-04-22 13:11:11 +05:30
let arg0 = ($rest | append '~').0
2022-12-08 23:24:43 +05:30
let path = if (($rest | length) <= 1) and ($arg0 == '-' or ($arg0 | path expand | path type) == dir) {
2022-04-22 13:11:11 +05:30
$arg0
} else {
(zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n")
2022-04-22 13:11:11 +05:30
}
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.
2024-02-16 02:31:47 +05:30
def --env __zoxide_zi [...rest:string] {
cd $'(zoxide query --interactive -- ...$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):
#
2023-01-07 22:58:10 +05:30
# zoxide init nushell | save -f ~/.zoxide.nu
2022-04-22 13:11:11 +05:30
#
# 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
#
# Note: zoxide only supports Nushell v0.89.0+.