2021-04-08 18:35:42 +00:00
|
|
|
{%- let section = "# =============================================================================\n#" -%}
|
|
|
|
{%- let not_configured = "# -- not configured --" -%}
|
2020-10-18 09:22:13 +00:00
|
|
|
|
2021-04-08 18:35:42 +00:00
|
|
|
{{ section }}
|
2020-10-18 09:22:13 +00:00
|
|
|
# Utility functions for zoxide.
|
|
|
|
#
|
|
|
|
|
|
|
|
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
|
|
|
|
function __zoxide_pwd
|
|
|
|
{%- if resolve_symlinks %}
|
2021-02-17 14:04:47 +00:00
|
|
|
builtin pwd -P
|
2020-10-18 09:22:13 +00:00
|
|
|
{%- else %}
|
2021-02-17 14:04:47 +00:00
|
|
|
builtin pwd -L
|
2020-10-18 09:22:13 +00:00
|
|
|
{%- endif %}
|
|
|
|
end
|
|
|
|
|
2021-05-09 19:46:25 +00:00
|
|
|
# A copy of fish's internal cd function. This makes it possible to use
|
|
|
|
# `alias cd=z` without causing an infinite loop.
|
2021-05-09 20:09:01 +00:00
|
|
|
if ! builtin functions -q __zoxide_cd_internal
|
|
|
|
if builtin functions -q cd
|
|
|
|
builtin functions -c cd __zoxide_cd_internal
|
|
|
|
else
|
|
|
|
alias __zoxide_cd_internal="builtin cd"
|
|
|
|
end
|
2021-05-09 19:46:25 +00:00
|
|
|
end
|
|
|
|
|
2020-10-18 09:22:13 +00:00
|
|
|
# cd + custom logic based on the value of _ZO_ECHO.
|
|
|
|
function __zoxide_cd
|
2021-05-09 19:46:25 +00:00
|
|
|
__zoxide_cd_internal $argv
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- if echo %}
|
2020-10-18 09:22:13 +00:00
|
|
|
and __zoxide_pwd
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- endif %}
|
2021-02-17 14:04:47 +00:00
|
|
|
and builtin commandline -f repaint
|
2020-10-18 09:22:13 +00:00
|
|
|
end
|
|
|
|
|
2021-04-08 18:35:42 +00:00
|
|
|
{{ section }}
|
2020-10-18 09:22:13 +00:00
|
|
|
# Hook configuration for zoxide.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Initialize hook to add new entries to the database.
|
2021-04-04 14:36:44 +00:00
|
|
|
if test "$__zoxide_hooked" != 1
|
|
|
|
set __zoxide_hooked 1
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- match hook %}
|
2021-05-03 21:12:43 +00:00
|
|
|
{%- when InitHook::None %}
|
2021-03-06 12:55:13 +00:00
|
|
|
function __zoxide_hook
|
2021-05-03 21:12:43 +00:00
|
|
|
{%- when InitHook::Prompt %}
|
2021-03-06 12:55:13 +00:00
|
|
|
function __zoxide_hook --on-event fish_prompt
|
2021-05-03 21:12:43 +00:00
|
|
|
{%- when InitHook::Pwd %}
|
2021-03-06 12:55:13 +00:00
|
|
|
function __zoxide_hook --on-variable PWD
|
2021-04-08 18:35:42 +00:00
|
|
|
{%- endmatch %}
|
2021-05-18 02:21:41 +00:00
|
|
|
test -z "$fish_private_mode"
|
|
|
|
and command zoxide add -- (__zoxide_pwd)
|
2021-03-06 12:55:13 +00:00
|
|
|
end
|
2020-10-18 09:22:13 +00:00
|
|
|
end
|
|
|
|
|
2021-04-08 18:35:42 +00:00
|
|
|
{{ section }}
|
2020-10-18 09:22:13 +00:00
|
|
|
# When using zoxide with --no-aliases, alias these internal functions as
|
|
|
|
# desired.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Jump to a directory using only keywords.
|
|
|
|
function __zoxide_z
|
|
|
|
set argc (count $argv)
|
|
|
|
if test $argc -eq 0
|
|
|
|
__zoxide_cd $HOME
|
2021-04-12 20:27:36 +00:00
|
|
|
else if test "$argv" = -
|
2020-10-18 09:22:13 +00:00
|
|
|
__zoxide_cd -
|
2021-04-04 14:36:44 +00:00
|
|
|
else if begin
|
|
|
|
test $argc -eq 1; and test -d $argv[1]
|
|
|
|
end
|
2020-10-26 17:55:04 +00:00
|
|
|
__zoxide_cd $argv[1]
|
2020-10-18 09:22:13 +00:00
|
|
|
else
|
2021-09-04 10:31:50 +00:00
|
|
|
set -l result (command zoxide query --exclude (__zoxide_pwd) -- $argv)
|
|
|
|
and __zoxide_cd $result
|
2020-10-18 09:22:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Jump to a directory using interactive search.
|
|
|
|
function __zoxide_zi
|
2021-09-04 10:31:50 +00:00
|
|
|
set -l result (command zoxide query -i -- $argv)
|
|
|
|
and __zoxide_cd $result
|
2020-10-18 09:22:13 +00:00
|
|
|
end
|
|
|
|
|
2021-04-08 18:35:42 +00:00
|
|
|
{{ section }}
|
2020-10-18 09:22:13 +00:00
|
|
|
# Convenient aliases for zoxide. Disable these using --no-aliases.
|
|
|
|
#
|
|
|
|
|
|
|
|
{%- match cmd %}
|
|
|
|
{%- when Some with (cmd) %}
|
|
|
|
|
2021-05-09 20:09:01 +00:00
|
|
|
# Remove definitions.
|
|
|
|
function __zoxide_unset
|
|
|
|
set --erase $argv >/dev/null 2>&1
|
|
|
|
abbr --erase $argv >/dev/null 2>&1
|
|
|
|
builtin functions --erase $argv >/dev/null 2>&1
|
|
|
|
end
|
|
|
|
|
2021-04-04 14:36:44 +00:00
|
|
|
__zoxide_unset {{cmd}}
|
2021-05-09 19:46:25 +00:00
|
|
|
alias {{cmd}}="__zoxide_z"
|
2020-10-18 09:22:13 +00:00
|
|
|
|
2021-04-04 14:36:44 +00:00
|
|
|
__zoxide_unset {{cmd}}i
|
2021-05-09 19:46:25 +00:00
|
|
|
alias {{cmd}}i="__zoxide_zi"
|
2020-10-18 09:22:13 +00:00
|
|
|
|
|
|
|
{%- when None %}
|
2021-04-08 18:35:42 +00:00
|
|
|
|
|
|
|
{{ not_configured }}
|
2020-10-18 09:22:13 +00:00
|
|
|
|
|
|
|
{%- endmatch %}
|
|
|
|
|
2021-04-08 18:35:42 +00:00
|
|
|
{{ section }}
|
2021-04-27 12:07:38 +00:00
|
|
|
# To initialize zoxide, add this to your configuration (usually
|
|
|
|
# ~/.config/fish/config.fish):
|
2020-10-18 09:22:13 +00:00
|
|
|
#
|
|
|
|
# zoxide init fish | source
|