Add hooks for Elvish
This commit is contained in:
parent
638d804613
commit
8452961904
|
|
@ -139,13 +139,13 @@ mod tests {
|
|||
let opts = dbg!(&opts()[i]);
|
||||
let mut source = String::new();
|
||||
|
||||
// Filter out lines using edit:add-var, since that function
|
||||
// is only available in the interactive editor.
|
||||
// Filter out lines using edit:*, since those functions
|
||||
// are only available in the interactive editor.
|
||||
for line in Elvish(opts)
|
||||
.render()
|
||||
.unwrap()
|
||||
.split('\n')
|
||||
.filter(|line| !line.starts_with("edit:add-var"))
|
||||
.filter(|line| !line.contains("edit:"))
|
||||
{
|
||||
source.push_str(line);
|
||||
source.push('\n');
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ function __zoxide_hook() {
|
|||
zoxide add -- "${__zoxide_pwd_old}"
|
||||
fi
|
||||
}
|
||||
|
||||
{%- endmatch %}
|
||||
|
||||
# Initialize hook.
|
||||
|
|
@ -113,6 +114,7 @@ function {{cmd}}i() {
|
|||
}
|
||||
|
||||
{%- when None %}
|
||||
|
||||
{{ not_configured }}
|
||||
|
||||
{%- endmatch %}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,15 @@ if (not (and (builtin:has-env __zoxide_hooked) (builtin:eq (builtin:get-env __zo
|
|||
builtin:set-env __zoxide_oldpwd $pwd
|
||||
before-chdir = [$@before-chdir [_]{ builtin:set-env __zoxide_oldpwd $pwd }]
|
||||
|
||||
# edit:before-readline = [{ echo 'going to read' }]
|
||||
# after-chdir = [[dir]{ zoxide add $pwd }]
|
||||
# Initialize hook to add directories to zoxide.
|
||||
{%- 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 }}
|
||||
|
|
@ -67,6 +74,7 @@ edit:add-var z~ $__zoxide_z~
|
|||
edit:add-var zi~ $__zoxide_zi~
|
||||
|
||||
{%- when None %}
|
||||
|
||||
{{ not_configured }}
|
||||
|
||||
{%- endmatch %}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@
|
|||
# Utility functions for zoxide.
|
||||
#
|
||||
|
||||
# Remove definitions.
|
||||
|
||||
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
|
||||
function __zoxide_pwd
|
||||
{%- if resolve_symlinks %}
|
||||
|
|
@ -99,6 +97,7 @@ function {{cmd}}i
|
|||
end
|
||||
|
||||
{%- when None %}
|
||||
|
||||
{{ not_configured }}
|
||||
|
||||
{%- endmatch %}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ alias {{cmd}} = __zoxide_z ''
|
|||
alias {{cmd}}i = __zoxide_zi ''
|
||||
|
||||
{%- when None %}
|
||||
|
||||
{{ not_configured }}
|
||||
|
||||
{%- endmatch %}
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ __zoxide_unset '{{cmd}}i'
|
|||
}
|
||||
|
||||
{%- when None %}
|
||||
|
||||
{{ not_configured }}
|
||||
|
||||
{%- endmatch %}
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ Set-Alias {{cmd}} __zoxide_z
|
|||
Set-Alias {{cmd}}i __zoxide_zi
|
||||
|
||||
{%- when None %}
|
||||
|
||||
{{ not_configured }}
|
||||
|
||||
{%- endmatch %}
|
||||
|
|
|
|||
|
|
@ -87,13 +87,12 @@ def __zoxide_errhandler(func):
|
|||
# Initialize hook to add new entries to the database.
|
||||
if globals().get("__zoxide_hooked") is not True:
|
||||
globals()["__zoxide_hooked"] = True
|
||||
|
||||
{% match hook -%}
|
||||
{%- when Hook::None -%}
|
||||
{%- when Hook::None %}
|
||||
{{ not_configured }}
|
||||
{%- when Hook::Prompt -%}
|
||||
{%- when Hook::Prompt %}
|
||||
@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
|
||||
{%- endmatch %}
|
||||
def __zoxide_hook(**_kwargs):
|
||||
|
|
@ -158,6 +157,7 @@ aliases["{{cmd}}"] = __zoxide_z
|
|||
aliases["{{cmd}}i"] = __zoxide_zi
|
||||
|
||||
{%- when None %}
|
||||
|
||||
{{ not_configured }}
|
||||
|
||||
{%- endmatch %}
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ function {{cmd}}i() {
|
|||
}
|
||||
|
||||
{%- when None %}
|
||||
|
||||
{{ not_configured }}
|
||||
|
||||
{%- endmatch %}
|
||||
|
|
|
|||
Loading…
Reference in New Issue