Skip to content

Commit

Permalink
[fish] Use set instead of read for $result
Browse files Browse the repository at this point in the history
This effectively makes CTRL-R non-blocking (the previous attempt was
unsuccessful).
  • Loading branch information
bitraid committed Jan 18, 2025
1 parent f46f98b commit 1c48fa6
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions shell/key-bindings.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1c48fa6

Please sign in to comment.