Add PWD hooks to Nushell (#439)

This commit is contained in:
Ajeet D'Souza 2022-08-13 02:02:43 +05:30
parent b0c899b99f
commit b38b89eb3b
4 changed files with 29 additions and 30 deletions

View File

@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased ## Unreleased
### Added
- Nushell: support for `z -`.
- Nushell: support for PWD hooks.
### Changed ### Changed
- Fish: change fuzzy completion prefix to `z!`. - 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. - Bash/Fish/Posix/Zsh: paths on Cygwin.
- Fish: completions not working on certain systems. - Fish: completions not working on certain systems.
- Bash: completions not escaping spaces correctly. - Bash: completions not escaping spaces correctly.
- Nushell: support for `z -`.
## [0.8.1] - 2021-04-23 ## [0.8.1] - 2021-04-23

View File

@ -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): Add this to your env file (find it by running `$nu.env-path` in Nushell):
```sh ```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 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 source ~/.zoxide.nu
``` ```
Note: zoxide only supports Nushell v0.62.0 and above. Note: zoxide only supports Nushell v0.63.0 and above.
</details> </details>

View File

@ -45,7 +45,7 @@ Now, add this to the end of your config file (find it by running
\fBsource ~/.zoxide.nu\fR \fBsource ~/.zoxide.nu\fR
.fi .fi
.sp .sp
Note: zoxide only supports Nushell v0.62.0 and above. Note: zoxide only supports Nushell v0.63.0 and above.
.TP .TP
.B powershell .B powershell
Add this to your configuration (find it by running \fBecho $profile\fR in Add this to your configuration (find it by running \fBecho $profile\fR in

View File

@ -6,35 +6,30 @@
{{ section }} {{ section }}
# Hook configuration for zoxide. # Hook configuration for zoxide.
# #
{% match hook %}
{%- when InitHook::None %} {% if hook == InitHook::None -%}
{{ not_configured }} {{ not_configured }}
{%- when InitHook::Prompt %} {%- else -%}
# Default prompt for Nushell. # Initialize hook to add new entries to the database.
let-env __zoxide_oldprompt = (if '__zoxide_oldprompt' in (env).name { {%- if hook == InitHook::Prompt %}
$env.__zoxide_oldprompt let-env config = ($env | default {} config).config
} else if 'PROMPT_COMMAND' in (env).name { let-env config = ($env.config | default {} hooks)
$env.PROMPT_COMMAND let-env config = ($env.config | update hooks ($env.config.hooks | default [] pre_prompt))
} else { let-env config = ($env.config | update hooks.pre_prompt ($env.config.hooks.pre_prompt | append {
{ $env.PWD }
})
# Hook to add new entries to the database.
def __zoxide_hook [] {
zoxide add -- $env.PWD 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. {%- endif %}
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 %}
{{ section }} {{ section }}
# When using zoxide with --no-cmd, alias these internal functions as desired. # When using zoxide with --no-cmd, alias these internal functions as desired.
@ -89,4 +84,4 @@ alias {{cmd}}i = __zoxide_zi
# #
# source ~/.zoxide.nu # source ~/.zoxide.nu
# #
# Note: zoxide only supports Nushell v0.62.0 and above. # Note: zoxide only supports Nushell v0.63.0 and above.