2e3230974c
Previous to this commit, tab completion and auto-suggestions for cd/z were inconsistent — only one or two of: CWD, CDPATH, and zoxide frecency results would work at a time, with different sourced matches shown in tab completion, shown in auto-suggest, and execution after pressing <Enter>. - Add _zoxide_z_complete in functions/zoxide.fish that merges all three sources into a single completion list (CWD via __fish_complete_cd, CDPATH via __fish_complete_directories, zoxide via query -l capped at 25) - Wire the new completer to both z and cd via complete directives in conf.d/zoxide.fish, replacing the previous incomplete approach - Add completions/zoxide.fish for full tab completion of the zoxide CLI itself (add, query, remove, import, init subcommands) - Update README to document the unified completion behavior and fix structural issues in Personalization/Attribution/Dependencies sections
69 lines
2.0 KiB
Fish
69 lines
2.0 KiB
Fish
# Adapted from icezyclon/zoxide.fish (MIT)
|
|
# Heavily customized for Fish 4.x compatibility and performance
|
|
|
|
if status is-interactive
|
|
|
|
if type -q zoxide
|
|
|
|
# -------------
|
|
# 'zoxide init fish' is very different for different versions of zoxide
|
|
# to guarantee the same behavior we define these functions ourself,
|
|
# especially because the apt package is so old
|
|
# most of these functions were taken from https://github.com/ajeetdsouza/zoxide
|
|
# from version 0.8.1
|
|
|
|
if ! builtin functions -q _zoxide_cd
|
|
if builtin functions -q cd
|
|
builtin functions -c cd _zoxide_cd
|
|
else
|
|
alias _zoxide_cd='builtin cd'
|
|
end
|
|
end
|
|
|
|
function _zoxide_hook --on-variable PWD
|
|
test -z "$fish_private_mode"
|
|
and command zoxide add -- (builtin pwd -L)
|
|
end
|
|
|
|
function z
|
|
set argc (count $argv)
|
|
if test $argc -eq 0
|
|
_zoxide_cd $HOME
|
|
else if test "$argv" = -
|
|
_zoxide_cd -
|
|
else if test -d $argv[-1]
|
|
_zoxide_cd $argv[-1]
|
|
else
|
|
set -l result (command zoxide query $argv)
|
|
and _zoxide_cd $result
|
|
end
|
|
end
|
|
|
|
function zi
|
|
set -l result (command zoxide query -i -- $argv)
|
|
and _zoxide_cd $result
|
|
end
|
|
|
|
# -------------
|
|
|
|
alias cd=z
|
|
|
|
# use custom completion
|
|
complete -c z -f # disable files by default
|
|
complete -c z -x -a '(_zoxide_z_complete)'
|
|
else
|
|
echo "[plugin: zoxide] Command 'zoxide' cannot be found. Not installed or not in path"
|
|
end
|
|
|
|
end
|
|
|
|
function _zoxide_uninstall --on-event zoxide_uninstall
|
|
if alias | grep "alias cd z" >/dev/null
|
|
functions -e cd
|
|
end
|
|
if builtin functions -q _zoxide_cd && not functions -q cd
|
|
# restore old cd
|
|
builtin functions -c _zoxide_cd cd
|
|
end
|
|
end
|