diff --git a/CHANGELOG.md b/CHANGELOG.md index abfcee7..bf1e784 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Nushell: upgrade minimum supported version to v0.73.0. - Zsh: fix extra space in interactive completions when no match is found. - Fzf: various improvements. +- Nushell: Accidental redefinition of hooks when initialized twice. ### Removed diff --git a/man/man1/zoxide-init.1 b/man/man1/zoxide-init.1 index 0d7f51b..e3331fb 100644 --- a/man/man1/zoxide-init.1 +++ b/man/man1/zoxide-init.1 @@ -35,7 +35,7 @@ Note: zoxide only supports fish v3.4.0 and above. Add this to your env file (find it by running \fB$nu.env-path\fR in Nushell): .sp .nf - \fBzoxide init nushell --hook prompt | save -f ~/.zoxide.nu\fR + \fBzoxide init nushell | save -f ~/.zoxide.nu\fR .fi .sp Now, add this to the end of your config file (find it by running diff --git a/src/config.rs b/src/config.rs index d7980fb..c5cb6ae 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; use anyhow::{Context, Result}; use glob::Pattern; -use crate::db2::Rank; +use crate::db::Rank; pub fn data_dir() -> Result { let path = match env::var_os("_ZO_DATA_DIR") { diff --git a/templates/nushell.txt b/templates/nushell.txt index df39c29..27310c0 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -12,22 +12,25 @@ {%- else -%} # Initialize hook to add new entries to the database. +if (not ($env | default false __zoxide_hooked | get __zoxide_hooked)) { + let-env __zoxide_hooked = true {%- if hook == InitHook::Prompt %} -let-env config = ($env | default {} config).config -let-env config = ($env.config | default {} hooks) -let-env config = ($env.config | update hooks ($env.config.hooks | default [] pre_prompt)) -let-env config = ($env.config | update hooks.pre_prompt ($env.config.hooks.pre_prompt | append { - zoxide add -- $env.PWD -})) + let-env config = ($env | default {} config).config + let-env config = ($env.config | default {} hooks) + let-env config = ($env.config | update hooks ($env.config.hooks | default [] pre_prompt)) + let-env config = ($env.config | update hooks.pre_prompt ($env.config.hooks.pre_prompt | append { + zoxide add -- $env.PWD + })) {%- else if hook == InitHook::Pwd %} -let-env config = ($env | default {} config).config -let-env config = ($env.config | default {} hooks) -let-env config = ($env.config | update hooks ($env.config.hooks | default {} env_change)) -let-env config = ($env.config | update hooks.env_change ($env.config.hooks.env_change | default [] PWD)) -let-env config = ($env.config | update hooks.env_change.PWD ($env.config.hooks.env_change.PWD | append {|_, dir| - zoxide add -- $dir -})) + let-env config = ($env | default {} config).config + let-env config = ($env.config | default {} hooks) + let-env config = ($env.config | update hooks ($env.config.hooks | default {} env_change)) + let-env config = ($env.config | update hooks.env_change ($env.config.hooks.env_change | default [] PWD)) + let-env config = ($env.config | update hooks.env_change.PWD ($env.config.hooks.env_change.PWD | append {|_, dir| + zoxide add -- $dir + })) {%- endif %} +} {%- endif %} @@ -77,7 +80,7 @@ alias {{cmd}}i = __zoxide_zi {{ section }} # Add this to your env file (find it by running `$nu.env-path` in Nushell): # -# zoxide init nushell --hook prompt | save -f ~/.zoxide.nu +# zoxide init nushell | save -f ~/.zoxide.nu # # Now, add this to the end of your config file (find it by running # `$nu.config-path` in Nushell):