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
46 lines
1.6 KiB
Fish
46 lines
1.6 KiB
Fish
# Adapted from icezyclon/zoxide.fish (MIT)
|
|
# Heavily customized for Fish 4.x compatibility and performance
|
|
|
|
function _zoxide_z_complete -d "Complete directory first or zoxide queries otherwise" --argument-names comp desc
|
|
# comp is the currently completing token
|
|
if not set -q comp[1]
|
|
set comp (commandline -ct)
|
|
end
|
|
# cmd are all tokens including the current one except the command
|
|
set -l cmd (commandline -opc) $comp
|
|
set -e cmd[1]
|
|
|
|
# 1. Get standard completions (CWD, CDPATH, etc.)
|
|
# We call the underlying functions directly to avoid recursion.
|
|
if test (count $cmd) -le 1
|
|
# CDPATH results
|
|
__fish_complete_cd
|
|
# Local directory results (CWD)
|
|
__fish_complete_directories "$comp" ""
|
|
end
|
|
|
|
# 2. Get zoxide results
|
|
# Cap results to 25 to avoid overwhelming the completion engine
|
|
set -l zresults (zoxide query -l $cmd | head -n 25)
|
|
for res in $zresults
|
|
set -l bname (basename $res)
|
|
# If the basename matches the prefix, show it as a short name.
|
|
if string match -qi "$comp*" -- $bname
|
|
printf "%s/\tzoxide: %s\n" $bname $res
|
|
end
|
|
# Also provide the absolute path. Fish will filter it if it doesn't match.
|
|
printf "%s/\tzoxide\n" $res
|
|
end
|
|
end
|
|
|
|
function _zoxide_equals_first_token -a check -d "Test if first non-switch token equals given one"
|
|
set -l tokens (commandline -co)
|
|
set -e tokens[1]
|
|
set -l tokens (string replace -r --filter '^([^-].*)' '$1' -- $tokens)
|
|
if set -q tokens[1]
|
|
test $tokens[1] = $check
|
|
else
|
|
return 1
|
|
end
|
|
end
|