2021-04-08 18:35:42 +00:00
|
|
|
{%- let section = "# =============================================================================\n#" -%}
|
|
|
|
{%- let not_configured = "# -- not configured --" -%}
|
|
|
|
|
|
|
|
use builtin
|
|
|
|
use path
|
|
|
|
|
|
|
|
{{ section }}
|
|
|
|
# Utility functions for zoxide.
|
|
|
|
#
|
|
|
|
|
|
|
|
# cd + custom logic based on the value of _ZO_ECHO.
|
|
|
|
fn __zoxide_cd [path]{
|
|
|
|
builtin:cd $path
|
|
|
|
{%- if echo %}
|
|
|
|
builtin:echo $pwd
|
|
|
|
{%- endif %}
|
|
|
|
}
|
|
|
|
|
|
|
|
{{ section }}
|
|
|
|
# Hook configuration for zoxide.
|
|
|
|
#
|
|
|
|
|
|
|
|
if (not (and (builtin:has-env __zoxide_hooked) (builtin:eq (builtin:get-env __zoxide_hooked) 1))) {
|
|
|
|
builtin:set-env __zoxide_hooked 1
|
|
|
|
|
|
|
|
# Initialize hook to track previous directory.
|
|
|
|
builtin:set-env __zoxide_oldpwd $pwd
|
|
|
|
before-chdir = [$@before-chdir [_]{ builtin:set-env __zoxide_oldpwd $pwd }]
|
|
|
|
|
|
|
|
# Initialize hook to add directories to zoxide.
|
|
|
|
{%- match hook %}
|
|
|
|
{%- when Hook::None %}
|
|
|
|
{{ not_configured }}
|
|
|
|
{%- when Hook::Prompt %}
|
2021-04-28 20:01:00 +00:00
|
|
|
edit:before-readline = [$@edit:before-readline []{ zoxide add -- $pwd }]
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- when Hook::Pwd %}
|
2021-04-28 20:01:00 +00:00
|
|
|
after-chdir = [$@after-chdir [_]{ zoxide add -- $pwd }]
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- endmatch %}
|
|
|
|
}
|
|
|
|
|
|
|
|
{{ section }}
|
|
|
|
# When using zoxide with --no-aliases, alias these internal functions as
|
|
|
|
# desired.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Jump to a directory using only keywords.
|
|
|
|
fn __zoxide_z [@rest]{
|
|
|
|
if (builtin:eq [] $rest) {
|
|
|
|
__zoxide_cd ~
|
|
|
|
} elif (builtin:eq [-] $rest) {
|
|
|
|
__zoxide_cd (builtin:get-env __zoxide_oldpwd)
|
|
|
|
} elif (and (builtin:eq (builtin:count $rest) 1) (path:is-dir $rest[0])) {
|
|
|
|
__zoxide_cd $rest[0]
|
|
|
|
} else {
|
|
|
|
__zoxide_cd (zoxide query --exclude $pwd -- $@rest)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
edit:add-var __zoxide_z~ $__zoxide_z~
|
|
|
|
|
|
|
|
# Jump to a directory using interactive search.
|
|
|
|
fn __zoxide_zi [@rest]{
|
|
|
|
__zoxide_cd (zoxide query -i -- $@rest)
|
|
|
|
}
|
|
|
|
edit:add-var __zoxide_zi~ $__zoxide_zi~
|
|
|
|
|
|
|
|
{{ section }}
|
|
|
|
# Convenient aliases for zoxide. Disable these using --no-aliases.
|
|
|
|
#
|
|
|
|
|
|
|
|
{%- match cmd %}
|
|
|
|
{%- when Some with (cmd) %}
|
|
|
|
|
|
|
|
edit:add-var z~ $__zoxide_z~
|
|
|
|
edit:add-var zi~ $__zoxide_zi~
|
|
|
|
|
|
|
|
{%- when None %}
|
|
|
|
|
|
|
|
{{ not_configured }}
|
|
|
|
|
|
|
|
{%- endmatch %}
|
|
|
|
|
|
|
|
{{ section }}
|
2021-04-27 12:07:38 +00:00
|
|
|
# To initialize zoxide, add this to your configuration (usually
|
|
|
|
# ~/.elvish/rc.elv):
|
2021-04-08 18:35:42 +00:00
|
|
|
#
|
|
|
|
# eval $(zoxide init elvish | slurp)
|