From 7acd099b3ec7570adb2d7e8b2db6371cef17f638 Mon Sep 17 00:00:00 2001 From: rootiest Date: Mon, 18 May 2026 20:37:18 -0400 Subject: [PATCH] fix(fzf): prefer bg-transform, fall back to transform on older fzf Detect fzf version once at shell startup inside fzf_key_bindings. Use bg-transform (non-blocking) on fzf >= 0.62 and the synchronous transform on older builds (e.g. 0.60 devel which lacks bg-transform). The chosen action is captured into fzf-history-widget via fish's --inherit-variable so the check runs once, not on every Ctrl+R press. --- integrations/fzf.fish | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/integrations/fzf.fish b/integrations/fzf.fish index 527f452..b1a2c1a 100644 --- a/integrations/fzf.fish +++ b/integrations/fzf.fish @@ -31,6 +31,14 @@ function fzf_key_bindings return 1 end + # bg-transform runs the preview toggle in a background thread (non-blocking). + # It was added after fzf 0.60; fall back to the synchronous transform on older builds. + set -l _fzf_ver (fzf --version | string match -r '^(\d+)\.(\d+)') + set -l _fzf_transform_action transform + if test -n "$_fzf_ver[3]"; and test "$_fzf_ver[3]" -ge 62 + set _fzf_transform_action bg-transform + end + #----BEGIN INCLUDE common.fish # NOTE: Do not directly edit this section, which is copied from "common.fish". # To modify it, one can edit "common.fish" and run "./update.sh" to apply @@ -177,7 +185,7 @@ function fzf_key_bindings commandline -f repaint end - function fzf-history-widget -d "Show command history" + function fzf-history-widget --inherit-variable _fzf_transform_action -d "Show command history" set -l -- command_line (commandline) set -l -- current_line (commandline -L) set -l -- total_lines (count $command_line) @@ -206,7 +214,7 @@ function fzf_key_bindings # Prepend the options to allow user customizations set -p -- FZF_DEFAULT_OPTS \ - '--bind="focus,resize:transform:if test \\"$FZF_COLUMNS\\" -gt 100 -a \\\\( \\"$FZF_SELECT_COUNT\\" -gt 0 -o \\\\( -z \\"$FZF_WRAP\\" -a (string length -- {}) -gt (math $FZF_COLUMNS - 4) \\\\) -o (string collect -- {2..} | fish_indent | count) -gt 1 \\\\); echo show-preview; else echo hide-preview; end"' \ + '--bind="focus,resize:'$_fzf_transform_action':if test \\"$FZF_COLUMNS\\" -gt 100 -a \\\\( \\"$FZF_SELECT_COUNT\\" -gt 0 -o \\\\( -z \\"$FZF_WRAP\\" -a (string length -- {}) -gt (math $FZF_COLUMNS - 4) \\\\) -o (string collect -- {2..} | fish_indent | count) -gt 1 \\\\); echo show-preview; else echo hide-preview; end"' \ '--preview="string collect -- (test \\"$FZF_SELECT_COUNT\\" -gt 0; and string collect -- {+2..}) \\"\\n# \\"'$date_cmd' {2..} | fish_indent --ansi"' \ '--preview-window="right,50%,wrap-word,follow,info,hidden"' end