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
|
2022-04-26 14:40:27 +00:00
|
|
|
{%- if cfg!(windows) %}
|
|
|
|
command cygpath -w (builtin pwd -P)
|
|
|
|
{%- else 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
|
2021-09-18 17:26:43 +00:00
|
|
|
alias __zoxide_cd_internal='builtin cd'
|
2021-05-09 20:09:01 +00:00
|
|
|
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
|
2022-04-26 14:40:27 +00:00
|
|
|
{%- if cfg!(windows) %}
|
|
|
|
__zoxide_cd_internal (cygpath -u $argv)
|
|
|
|
{%- else %}
|
2021-05-09 19:46:25 +00:00
|
|
|
__zoxide_cd_internal $argv
|
2022-04-26 14:40:27 +00:00
|
|
|
{%- endif %}
|
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 %}
|
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.
|
|
|
|
#
|
|
|
|
|
2021-09-06 21:11:17 +00:00
|
|
|
{% if hook == InitHook::None -%}
|
|
|
|
{{ not_configured }}
|
|
|
|
|
|
|
|
{%- else -%}
|
2020-10-18 09:22:13 +00:00
|
|
|
# Initialize hook to add new entries to the database.
|
2021-09-06 21:11:17 +00:00
|
|
|
{%- if hook == InitHook::Prompt %}
|
|
|
|
function __zoxide_hook --on-event fish_prompt
|
|
|
|
{%- else if hook == InitHook::Pwd %}
|
|
|
|
function __zoxide_hook --on-variable PWD
|
|
|
|
{%- endif %}
|
|
|
|
test -z "$fish_private_mode"
|
|
|
|
and command zoxide add -- (__zoxide_pwd)
|
2020-10-18 09:22:13 +00:00
|
|
|
end
|
|
|
|
|
2021-09-06 21:11:17 +00:00
|
|
|
{%- endif %}
|
|
|
|
|
2021-04-08 18:35:42 +00:00
|
|
|
{{ section }}
|
2022-04-22 07:41:11 +00:00
|
|
|
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
2020-10-18 09:22:13 +00:00
|
|
|
#
|
|
|
|
|
2022-07-04 09:05:41 +00:00
|
|
|
set __zoxide_z_prefix 'z!'
|
2022-04-27 13:35:52 +00:00
|
|
|
|
2020-10-18 09:22:13 +00:00
|
|
|
# Jump to a directory using only keywords.
|
|
|
|
function __zoxide_z
|
2022-04-27 13:35:52 +00:00
|
|
|
set -l argc (count $argv)
|
|
|
|
set -l completion_regex '^'(string escape --style=regex $__zoxide_z_prefix)'(.*)$'
|
|
|
|
|
2020-10-18 09:22:13 +00:00
|
|
|
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-09-18 17:26:43 +00:00
|
|
|
else if test $argc -eq 1 -a -d $argv[1]
|
2020-10-26 17:55:04 +00:00
|
|
|
__zoxide_cd $argv[1]
|
2022-04-27 13:35:52 +00:00
|
|
|
else if set -l result (string match --groups-only --regex $completion_regex $argv[-1])
|
|
|
|
__zoxide_cd $result
|
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
|
|
|
|
|
2021-09-18 17:26:43 +00:00
|
|
|
# Completions for `z`.
|
|
|
|
function __zoxide_z_complete
|
2021-12-29 22:32:23 +00:00
|
|
|
set -l tokens (commandline --current-process --tokenize)
|
|
|
|
set -l curr_tokens (commandline --cut-at-cursor --current-process --tokenize)
|
2021-09-18 17:26:43 +00:00
|
|
|
|
2021-10-31 14:46:40 +00:00
|
|
|
if test (count $tokens) -le 2 -a (count $curr_tokens) -eq 1
|
2021-12-02 22:21:19 +00:00
|
|
|
# If there are < 2 arguments, use `cd` completions.
|
2021-10-31 14:46:40 +00:00
|
|
|
__fish_complete_directories "$tokens[2]" ''
|
2021-12-02 22:21:19 +00:00
|
|
|
else if test (count $tokens) -eq (count $curr_tokens)
|
|
|
|
# If the last argument is empty, use interactive selection.
|
2021-10-31 14:46:40 +00:00
|
|
|
set -l query $tokens[2..-1]
|
2022-04-27 13:35:52 +00:00
|
|
|
set -l result (zoxide query --exclude (__zoxide_pwd) -i -- $query)
|
|
|
|
and echo $__zoxide_z_prefix$result
|
2022-03-09 08:13:52 +00:00
|
|
|
commandline --function repaint
|
2021-09-18 17:26:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-18 09:22:13 +00:00
|
|
|
# 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 }}
|
2022-04-10 22:11:51 +00:00
|
|
|
# Commands for zoxide. Disable these using --no-cmd.
|
2020-10-18 09:22:13 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
{%- match cmd %}
|
|
|
|
{%- when Some with (cmd) %}
|
|
|
|
|
2022-06-25 19:07:44 +00:00
|
|
|
abbr --erase {{cmd}} &>/dev/null
|
2022-07-27 08:31:14 +00:00
|
|
|
complete --command {{cmd}} --erase
|
2022-04-17 09:06:47 +00:00
|
|
|
function {{cmd}}
|
|
|
|
__zoxide_z $argv
|
2021-05-09 20:09:01 +00:00
|
|
|
end
|
2022-07-27 08:31:14 +00:00
|
|
|
complete --command {{cmd}} --no-files --arguments '(__zoxide_z_complete)'
|
2020-10-18 09:22:13 +00:00
|
|
|
|
2022-06-25 19:07:44 +00:00
|
|
|
abbr --erase {{cmd}}i &>/dev/null
|
2022-07-27 08:31:14 +00:00
|
|
|
complete --command {{cmd}}i --erase
|
2022-04-17 09:06:47 +00:00
|
|
|
function {{cmd}}i
|
|
|
|
__zoxide_zi $argv
|
|
|
|
end
|
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
|
|
|
#
|
2022-07-01 09:33:30 +00:00
|
|
|
# zoxide init fish | source
|
|
|
|
#
|
|
|
|
# Note: zoxide only supports fish v3.4.0 and above.
|