116 lines
2.7 KiB
Plaintext
116 lines
2.7 KiB
Plaintext
{%- 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.
|
|
#
|
|
|
|
# Initialize hook to track previous directory.
|
|
__zoxide_oldpwd = $pwd
|
|
before-chdir = [$@before-chdir [_]{ edit:add-var __zoxide_oldpwd $pwd }]
|
|
|
|
{#- __zoxide_hooked requires https://github.com/elves/elvish/issues/1395 #}
|
|
|
|
# Initialize hook to add directories to zoxide.
|
|
{%- match hook %}
|
|
{%- when InitHook::None %}
|
|
{{ not_configured }}
|
|
{%- when InitHook::Prompt %}
|
|
edit:before-readline = [$@edit:before-readline []{ zoxide add -- $pwd }]
|
|
{%- when InitHook::Pwd %}
|
|
after-chdir = [$@after-chdir [_]{ zoxide add -- $pwd }]
|
|
{%- 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 $__zoxide_oldpwd
|
|
} elif (and ('builtin:==' (builtin:count $rest) 1) (path:is-dir &follow-symlink=$true $rest[0])) {
|
|
__zoxide_cd $rest[0]
|
|
} else {
|
|
var path
|
|
try {
|
|
path = (zoxide query --exclude $pwd -- $@rest)
|
|
} except {
|
|
} else {
|
|
__zoxide_cd $path
|
|
}
|
|
}
|
|
}
|
|
edit:add-var __zoxide_z~ $__zoxide_z~
|
|
|
|
# Jump to a directory using interactive search.
|
|
fn __zoxide_zi [@rest]{
|
|
var path
|
|
try {
|
|
path = (zoxide query -i -- $@rest)
|
|
} except {
|
|
} else {
|
|
__zoxide_cd $path
|
|
}
|
|
}
|
|
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 {{cmd}}~ $__zoxide_z~
|
|
edit:add-var {{cmd}}i~ $__zoxide_zi~
|
|
|
|
# Load completions.
|
|
{# zoxide-based completions are currently not possible, because Elvish only
|
|
# prints a completion if the current token is a prefix of it. -#}
|
|
fn __zoxide_z_complete [@args]{
|
|
if (!= (count $args) 2) {
|
|
return
|
|
}
|
|
edit:complete-filename $args[1] |
|
|
each [c]{
|
|
dir = $c[stem]
|
|
if (path:is-dir $dir) {
|
|
put $dir
|
|
}
|
|
}
|
|
}
|
|
edit:completion:arg-completer[{{cmd}}] = $__zoxide_z_complete~
|
|
|
|
{%- when None %}
|
|
|
|
{{ not_configured }}
|
|
|
|
{%- endmatch %}
|
|
|
|
{{ section }}
|
|
# To initialize zoxide, add this to your configuration (usually
|
|
# ~/.elvish/rc.elv):
|
|
#
|
|
# eval (zoxide init elvish | slurp)
|
|
#
|
|
# Note: zoxide only supports elvish v0.16.0 and above.
|