Files
archived-solorice/config/fish/functions/fzf_complete.fish
2026-02-09 22:52:34 +02:00

60 lines
1.8 KiB
Fish
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function fzf_complete --description "fzf-tab style completion for fish"
set -l cmd (commandline -opc)
set -l token (commandline -t)
# Get all fish completions for the current command line
set -l completions (complete -C(commandline -cp))
# If no completions, fallback to default behavior
if test (count $completions) -eq 0
commandline -f complete
return
end
# If only one completion, insert it directly
if test (count $completions) -eq 1
set -l comp (string split \t -- $completions[1])[1]
__insert_unquoted_path $comp
commandline -f repaint
return
end
# Multiple completions - show in fzf
set -l selected (
printf '%s\n' $completions |
fzf --ansi \
--height=50% \
--reverse \
--border \
--cycle \
--info=inline \
--tabstop=4 \
--prompt=' ' \
--pointer='▶' \
--marker='✓' \
--bind 'tab:down,btab:up' \
--preview-window='right:50%:wrap' \
--preview='
set item (string split \t {})[1]
set real (eval echo $item 2>/dev/null || echo $item)
if test -d "$real"
eza --color=always -la "$real" 2>/dev/null
else if test -f "$real"
bat --color=always --style=numbers --line-range=:500 "$real" 2>/dev/null || cat "$real"
else if test -e "$real"
ls -lah "$real"
else
echo "$item"
end
'
)
if test -n "$selected"
# Extract the actual completion (first field before tab)
set -l comp (string split \t -- $selected)[1]
__insert_unquoted_path $comp
end
commandline -f repaint
end