Add hooks for Elvish

This commit is contained in:
Ajeet D'Souza 2021-04-08 11:12:12 +05:30
parent 638d804613
commit 8452961904
9 changed files with 57 additions and 44 deletions

View File

@ -139,13 +139,13 @@ mod tests {
let opts = dbg!(&opts()[i]); let opts = dbg!(&opts()[i]);
let mut source = String::new(); let mut source = String::new();
// Filter out lines using edit:add-var, since that function // Filter out lines using edit:*, since those functions
// is only available in the interactive editor. // are only available in the interactive editor.
for line in Elvish(opts) for line in Elvish(opts)
.render() .render()
.unwrap() .unwrap()
.split('\n') .split('\n')
.filter(|line| !line.starts_with("edit:add-var")) .filter(|line| !line.contains("edit:"))
{ {
source.push_str(line); source.push_str(line);
source.push('\n'); source.push('\n');

View File

@ -44,6 +44,7 @@ function __zoxide_hook() {
zoxide add -- "${__zoxide_pwd_old}" zoxide add -- "${__zoxide_pwd_old}"
fi fi
} }
{%- endmatch %} {%- endmatch %}
# Initialize hook. # Initialize hook.
@ -113,6 +114,7 @@ function {{cmd}}i() {
} }
{%- when None %} {%- when None %}
{{ not_configured }} {{ not_configured }}
{%- endmatch %} {%- endmatch %}

View File

@ -27,8 +27,15 @@ if (not (and (builtin:has-env __zoxide_hooked) (builtin:eq (builtin:get-env __zo
builtin:set-env __zoxide_oldpwd $pwd builtin:set-env __zoxide_oldpwd $pwd
before-chdir = [$@before-chdir [_]{ builtin:set-env __zoxide_oldpwd $pwd }] before-chdir = [$@before-chdir [_]{ builtin:set-env __zoxide_oldpwd $pwd }]
# edit:before-readline = [{ echo 'going to read' }] # Initialize hook to add directories to zoxide.
# after-chdir = [[dir]{ zoxide add $pwd }] {%- match hook %}
{%- when Hook::None %}
{{ not_configured }}
{%- when Hook::Prompt %}
edit:before-readline = [$@edit:before-readline []{ zoxide add $pwd }]
{%- when Hook::Pwd %}
after-chdir = [$@after-chdir [_]{ zoxide add $pwd }]
{%- endmatch %}
} }
{{ section }} {{ section }}
@ -67,6 +74,7 @@ edit:add-var z~ $__zoxide_z~
edit:add-var zi~ $__zoxide_zi~ edit:add-var zi~ $__zoxide_zi~
{%- when None %} {%- when None %}
{{ not_configured }} {{ not_configured }}
{%- endmatch %} {%- endmatch %}

View File

@ -5,8 +5,6 @@
# Utility functions for zoxide. # Utility functions for zoxide.
# #
# Remove definitions.
# pwd based on the value of _ZO_RESOLVE_SYMLINKS. # pwd based on the value of _ZO_RESOLVE_SYMLINKS.
function __zoxide_pwd function __zoxide_pwd
{%- if resolve_symlinks %} {%- if resolve_symlinks %}
@ -99,6 +97,7 @@ function {{cmd}}i
end end
{%- when None %} {%- when None %}
{{ not_configured }} {{ not_configured }}
{%- endmatch %} {%- endmatch %}

View File

@ -73,6 +73,7 @@ alias {{cmd}} = __zoxide_z ''
alias {{cmd}}i = __zoxide_zi '' alias {{cmd}}i = __zoxide_zi ''
{%- when None %} {%- when None %}
{{ not_configured }} {{ not_configured }}
{%- endmatch %} {%- endmatch %}

View File

@ -109,6 +109,7 @@ __zoxide_unset '{{cmd}}i'
} }
{%- when None %} {%- when None %}
{{ not_configured }} {{ not_configured }}
{%- endmatch %} {%- endmatch %}

View File

@ -95,6 +95,7 @@ Set-Alias {{cmd}} __zoxide_z
Set-Alias {{cmd}}i __zoxide_zi Set-Alias {{cmd}}i __zoxide_zi
{%- when None %} {%- when None %}
{{ not_configured }} {{ not_configured }}
{%- endmatch %} {%- endmatch %}

View File

@ -87,13 +87,12 @@ def __zoxide_errhandler(func):
# Initialize hook to add new entries to the database. # Initialize hook to add new entries to the database.
if globals().get("__zoxide_hooked") is not True: if globals().get("__zoxide_hooked") is not True:
globals()["__zoxide_hooked"] = True globals()["__zoxide_hooked"] = True
{% match hook -%} {% match hook -%}
{%- when Hook::None -%} {%- when Hook::None %}
{{ not_configured }} {{ not_configured }}
{%- when Hook::Prompt -%} {%- when Hook::Prompt %}
@events.on_post_prompt # type: ignore # pylint:disable=undefined-variable @events.on_post_prompt # type: ignore # pylint:disable=undefined-variable
{%- when Hook::Pwd -%} {%- when Hook::Pwd %}
@events.on_chdir # type: ignore # pylint:disable=undefined-variable @events.on_chdir # type: ignore # pylint:disable=undefined-variable
{%- endmatch %} {%- endmatch %}
def __zoxide_hook(**_kwargs): def __zoxide_hook(**_kwargs):
@ -158,6 +157,7 @@ aliases["{{cmd}}"] = __zoxide_z
aliases["{{cmd}}i"] = __zoxide_zi aliases["{{cmd}}i"] = __zoxide_zi
{%- when None %} {%- when None %}
{{ not_configured }} {{ not_configured }}
{%- endmatch %} {%- endmatch %}

View File

@ -99,6 +99,7 @@ function {{cmd}}i() {
} }
{%- when None %} {%- when None %}
{{ not_configured }} {{ not_configured }}
{%- endmatch %} {%- endmatch %}