diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a3ad93..28f79cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Nushell: support for `z -`. +- Nushell: support for PWD hooks. + ### Changed - Fish: change fuzzy completion prefix to `z!`. @@ -30,7 +35,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bash/Fish/Posix/Zsh: paths on Cygwin. - Fish: completions not working on certain systems. - Bash: completions not escaping spaces correctly. -- Nushell: support for `z -`. ## [0.8.1] - 2021-04-23 diff --git a/README.md b/README.md index 542b380..27be36b 100644 --- a/README.md +++ b/README.md @@ -202,7 +202,7 @@ Note: zoxide only supports fish v3.4.0 and above. Add this to your env file (find it by running `$nu.env-path` in Nushell): ```sh -zoxide init nushell --hook prompt | save ~/.zoxide.nu +zoxide init nushell | save ~/.zoxide.nu ``` Now, add this to the end of your config file (find it by running @@ -212,7 +212,7 @@ Now, add this to the end of your config file (find it by running source ~/.zoxide.nu ``` -Note: zoxide only supports Nushell v0.62.0 and above. +Note: zoxide only supports Nushell v0.63.0 and above. diff --git a/man/man1/zoxide-init.1 b/man/man1/zoxide-init.1 index 0241b41..d15a302 100644 --- a/man/man1/zoxide-init.1 +++ b/man/man1/zoxide-init.1 @@ -45,7 +45,7 @@ Now, add this to the end of your config file (find it by running \fBsource ~/.zoxide.nu\fR .fi .sp -Note: zoxide only supports Nushell v0.62.0 and above. +Note: zoxide only supports Nushell v0.63.0 and above. .TP .B powershell Add this to your configuration (find it by running \fBecho $profile\fR in diff --git a/templates/nushell.txt b/templates/nushell.txt index b21f9cf..7576e6c 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -6,35 +6,30 @@ {{ section }} # Hook configuration for zoxide. # -{% match hook %} -{%- when InitHook::None %} + +{% if hook == InitHook::None -%} {{ not_configured }} -{%- when InitHook::Prompt %} -# 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. -def __zoxide_hook [] { +{%- else -%} +# Initialize hook to add new entries to the database. +{%- 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 -} +})) +{%- 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 +})) +{%- endif %} -# Initialize hook. -let-env PROMPT_COMMAND = { - __zoxide_hook - do $env.__zoxide_oldprompt -} - -{%- when InitHook::Pwd %} -echo "zoxide: PWD hooks are not supported on Nushell.\nUse `zoxide init nushell --hook prompt` instead." - -{%- endmatch %} +{%- endif %} {{ section }} # When using zoxide with --no-cmd, alias these internal functions as desired. @@ -89,4 +84,4 @@ alias {{cmd}}i = __zoxide_zi # # source ~/.zoxide.nu # -# Note: zoxide only supports Nushell v0.62.0 and above. +# Note: zoxide only supports Nushell v0.63.0 and above.