From 1c48fa6c36b1a7d9851bee1faf8d03bb57cb00a2 Mon Sep 17 00:00:00 2001 From: bitraid Date: Sat, 18 Jan 2025 11:04:32 +0200 Subject: [PATCH] [fish] Use `set` instead of `read` for `$result` This effectively makes CTRL-R non-blocking (the previous attempt was unsuccessful). --- shell/key-bindings.fish | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish index 9abfd0d7ea6..7e1d266224a 100644 --- a/shell/key-bindings.fish +++ b/shell/key-bindings.fish @@ -31,13 +31,14 @@ function fzf_key_bindings set -lx dir $commandline[1] set -l fzf_query $commandline[2] set -l prefix $commandline[3] + set -l result test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40% begin set -lx FZF_DEFAULT_OPTS (__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path --walker-root=$dir" "$FZF_CTRL_T_OPTS") set -lx FZF_DEFAULT_COMMAND "$FZF_CTRL_T_COMMAND" set -lx FZF_DEFAULT_OPTS_FILE '' - eval (__fzfcmd) -m --query=$fzf_query | while read -l r; set -a result $r; end + set result (eval (__fzfcmd) -m --query=$fzf_query) end if test -z "$result" commandline -f repaint @@ -62,18 +63,20 @@ function fzf_key_bindings set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"\t"↳ ' --highlight-line $FZF_CTRL_R_OPTS +m") set -lx FZF_DEFAULT_OPTS_FILE '' + set -lx FZF_DEFAULT_COMMAND + string match -q -r -- '/fish$' $SHELL; or set -lx SHELL (type -p fish) if type -q perl - set -l fzf_command (__fzfcmd) --tac --read0 --print0 -q (commandline) - builtin history -z --reverse | command perl -0 -pe 's/^/$.\t/g; s/\n/\n\t/gm' | $fzf_command | string replace -r '^\d*\t' '' | read -lz result - and commandline -- $result + set -a FZF_DEFAULT_OPTS '--tac' + set FZF_DEFAULT_COMMAND 'builtin history -z --reverse | command perl -0 -pe \'s/^/$.\t/g; s/\n/\n\t/gm\'' else - set -l h (builtin history -z | string split0) - set -l fzf_command (__fzfcmd) --read0 --print0 -q (commandline) - for i in (seq (count $h) -1 1) - string join0 -- $i\t(string replace -a -- \n \n\t $h[$i] | string collect) - end | $fzf_command | string replace -r '^\d*\t' '' | read -lz result - and commandline -- $result + set FZF_DEFAULT_COMMAND \ + 'set -l h (builtin history -z --reverse | string split0);' \ + 'for i in (seq (count $h) -1 1);' \ + 'string join0 -- $i\t(string replace -a -- \n \n\t $h[$i] | string collect);' \ + 'end' end + set -l result (eval "$FZF_DEFAULT_COMMAND | $(__fzfcmd) --read0 --print0 -q (commandline)") + and commandline -- (string replace -r -- '^\d*\t' '' $result) end commandline -f repaint end @@ -89,7 +92,7 @@ function fzf_key_bindings set -lx FZF_DEFAULT_OPTS (__fzf_defaults "--reverse --walker=dir,follow,hidden --scheme=path --walker-root=$dir" "$FZF_ALT_C_OPTS") set -lx FZF_DEFAULT_OPTS_FILE '' set -lx FZF_DEFAULT_COMMAND "$FZF_ALT_C_COMMAND" - eval (__fzfcmd) +m --query=$fzf_query | read -l result + set -l result (eval (__fzfcmd) +m --query=$fzf_query) if test -n "$result" cd -- $result