zoxide/templates/fish.txt

115 lines
2.6 KiB
Plaintext

{%- let section = "# =============================================================================\n#" -%}
{%- let not_configured = "# -- not configured --" -%}
{{ section }}
# Utility functions for zoxide.
#
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
function _zoxide_pwd
{%- if resolve_symlinks %}
builtin pwd -P
{%- else %}
builtin pwd -L
{%- endif %}
end
# A copy of fish's internal cd function. This makes it possible to use
# `alias cd=z` without causing an infinite loop.
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
end
# cd + custom logic based on the value of _ZO_ECHO.
function _zoxide_cd
_zoxide_cd_internal $argv
{%- if echo %}
and _zoxide_pwd
{%- endif %}
and builtin commandline -f repaint
end
{{ section }}
# Hook configuration for zoxide.
#
# Initialize hook to add new entries to the database.
if test "$_zoxide_hooked" != 1
set _zoxide_hooked 1
{%- match hook %}
{%- when InitHook::None %}
function _zoxide_hook
{%- when InitHook::Prompt %}
function _zoxide_hook --on-event fish_prompt
{%- when InitHook::Pwd %}
function _zoxide_hook --on-variable PWD
{%- endmatch %}
test -z "$fish_private_mode"
and command zoxide add -- (_zoxide_pwd)
end
end
{{ section }}
# 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
else if test "$argv" = -
_zoxide_cd -
else if begin
test $argc -eq 1; and test -d $argv[1]
end
_zoxide_cd $argv[1]
else
set -l _zoxide_result (command zoxide query --exclude (_zoxide_pwd) -- $argv)
and _zoxide_cd $_zoxide_result
end
end
# Jump to a directory using interactive search.
function _zoxide_zi
set -l _zoxide_result (command zoxide query -i -- $argv)
and _zoxide_cd $_zoxide_result
end
{{ section }}
# Convenient aliases for zoxide. Disable these using --no-aliases.
#
{%- match cmd %}
{%- when Some with (cmd) %}
# 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
_zoxide_unset {{cmd}}
alias {{cmd}}="_zoxide_z"
_zoxide_unset {{cmd}}i
alias {{cmd}}i="_zoxide_zi"
{%- when None %}
{{ not_configured }}
{%- endmatch %}
{{ section }}
# To initialize zoxide, add this to your configuration (usually
# ~/.config/fish/config.fish):
#
# zoxide init fish | source