zoxide/templates/fish.txt

157 lines
3.2 KiB
Plaintext
Raw Normal View History

2020-10-18 09:22:13 +00:00
{%- let SECTION = "# =============================================================================\n#" -%}
{%- let NOT_CONFIGURED = "# -- not configured --" -%}
{{ SECTION }}
# Utility functions for zoxide.
#
# Remove definitions.
2020-10-18 09:22:13 +00:00
# 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
# cd + custom logic based on the value of _ZO_ECHO.
function __zoxide_cd
2021-02-17 14:04:47 +00:00
builtin cd $argv
2020-10-18 09:22:13 +00:00
{%- if echo %}
and __zoxide_pwd
{%- endif %}
2021-02-17 14:04:47 +00:00
and builtin commandline -f repaint
2020-10-18 09:22:13 +00:00
end
{{ SECTION }}
# Hook configuration for zoxide.
#
# Initialize hook to add new entries to the database.
{%- match hook %}
{%- when Hook::None %}
function __zoxide_hook
{%- when Hook::Prompt %}
function __zoxide_hook --on-event fish_prompt
{%- when Hook::Pwd %}
function __zoxide_hook --on-variable PWD
{%- endmatch %}
2021-02-17 14:04:47 +00:00
command zoxide add (__zoxide_pwd)
2020-10-18 09:22:13 +00:00
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 begin; test $argc -eq 1; and test $argv[1] = '-'; end
__zoxide_cd -
else if begin; test $argc -eq 1; and test -d $argv[1]; end
__zoxide_cd $argv[1]
2020-10-18 09:22:13 +00:00
else
2021-02-17 14:04:47 +00:00
set -l __zoxide_result (command zoxide query -- $argv)
2020-10-18 09:22:13 +00:00
and __zoxide_cd $__zoxide_result
end
end
# Jump to a directory using interactive search.
function __zoxide_zi
2021-02-17 14:04:47 +00:00
set -l __zoxide_result (command zoxide query -i -- $argv)
2020-10-18 09:22:13 +00:00
and __zoxide_cd $__zoxide_result
end
# Add a new entry to the database.
function __zoxide_za
2021-02-17 14:04:47 +00:00
command zoxide add $argv
2020-10-18 09:22:13 +00:00
end
# Query an entry from the database using only keywords.
function __zoxide_zq
2021-02-17 14:04:47 +00:00
command zoxide query $argv
2020-10-18 09:22:13 +00:00
end
# Query an entry from the database using interactive selection.
function __zoxide_zqi
2021-02-17 14:04:47 +00:00
command zoxide query -i $argv
2020-10-18 09:22:13 +00:00
end
# Remove an entry from the database using the exact path.
function __zoxide_zr
2021-02-17 14:04:47 +00:00
command zoxide remove $argv
2020-10-18 09:22:13 +00:00
end
# Remove an entry from the database using interactive selection.
function __zoxide_zri
2021-02-17 14:04:47 +00:00
command zoxide remove -i $argv
2020-10-18 09:22:13 +00:00
end
{{ SECTION }}
# Convenient aliases for zoxide. Disable these using --no-aliases.
#
{%- match cmd %}
{%- when Some with (cmd) %}
# Remove definitions.
function __zoxide_unset
2021-03-01 06:10:10 +00:00
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}}'
2020-10-18 09:22:13 +00:00
function {{cmd}}
__zoxide_z $argv
end
__zoxide_unset '{{cmd}}i'
2020-10-18 09:22:13 +00:00
function {{cmd}}i
__zoxide_zi $argv
end
__zoxide_unset '{{cmd}}a'
2020-10-18 09:22:13 +00:00
function {{cmd}}a
__zoxide_za $argv
end
__zoxide_unset '{{cmd}}q'
2020-10-18 09:22:13 +00:00
function {{cmd}}q
__zoxide_zq $argv
end
__zoxide_unset '{{cmd}}qi'
2020-10-18 09:22:13 +00:00
function {{cmd}}qi
__zoxide_zqi $argv
end
__zoxide_unset '{{cmd}}r'
2020-10-18 09:22:13 +00:00
function {{cmd}}r
__zoxide_zr $argv
end
__zoxide_unset '{{cmd}}ri'
2020-10-18 09:22:13 +00:00
function {{cmd}}ri
__zoxide_zri $argv
end
{%- when None %}
{{ NOT_CONFIGURED }}
{%- endmatch %}
{{ SECTION }}
# To initialize zoxide with fish, add the following line to your fish
# configuration file (usually ~/.config/fish/config.fish):
#
# zoxide init fish | source