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
### 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

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):
```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.
</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
.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

View File

@ -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.