From ad151d84154632a6abec67b40fe326c1ea2c9481 Mon Sep 17 00:00:00 2001 From: bitraid Date: Mon, 7 Sep 2026 02:36:30 +0300 Subject: [PATCH] fish: Improve custom CTRL-T command execution (#4909) The custom CTRL-T command is now executed by the script in the current shell session, instead of being called by fzf through a subshell. This ensures that the value of $dir can't be altered by user initialization scripts, and is also a little faster. Fix #4498 --- CHANGELOG.md | 1 + shell/key-bindings.fish | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8bb7003..a2478871 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ CHANGELOG - fzf now opens in a tmux or Zellij floating pane by default, so the window it was started from stays visible and can be used while fzf is running - Requires tmux 3.7+ or Zellij 0.44+ - Set `g:fzf_layout` to pick a different layout +- fish: Fixed custom CTRL-T command not using the prefixed target directory in some cases (#4498) 0.74.3 ------ diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish index a9b9d14c..38f57b33 100644 --- a/shell/key-bindings.fish +++ b/shell/key-bindings.fish @@ -104,7 +104,7 @@ function fzf_key_bindings # Store current token in $dir as root for the 'find' command function fzf-file-widget -d "List files and folders" set -l commandline (__fzf_parse_commandline) - set -lx dir $commandline[1] + set -l dir $commandline[1] set -l fzf_query $commandline[2] set -l prefix $commandline[3] @@ -112,10 +112,17 @@ function fzf_key_bindings "--reverse --walker=file,dir,follow,hidden --scheme=path" \ "--multi $FZF_CTRL_T_OPTS --print0") - set -lx FZF_DEFAULT_COMMAND "$FZF_CTRL_T_COMMAND" set -lx FZF_DEFAULT_OPTS_FILE - set -l result (eval (__fzfcmd) --walker-root=$dir --query=$fzf_query | string split0) + set -lx FZF_DEFAULT_COMMAND + + if test -n "$FZF_CTRL_T_COMMAND" + set -f result (eval $FZF_CTRL_T_COMMAND \| (__fzfcmd) --query=$fzf_query | string split0) + else + set -f result (eval (__fzfcmd) --walker-root=$dir --query=$fzf_query | string split0) + end + + test -n "$result" and commandline -rt -- (string join -- ' ' $prefix(string escape -n -- $result))' ' commandline -f repaint