Skip to content

Commit 4e379cd

Browse files
committed
[fish] Use FZF_DEFAULT_COMMAND for history
This makes the loading of the list non-blocking, since the command is no longer piped to eval. It also allows users to easily set key bindings via FZF_CTRL_R_OPTS, that reload the history list. For example: ``` set -x FZF_CTRL_R_OPTS '--bind=\'ctrl-x:execute(history delete -- {2..})+reload(eval $FZF_DEFAULT_COMMAND)\'' ``` To properly handle multi-line entries thought, the execute command of the exapmle above, must become a little more complex: ``` eval history delete -- (string escape -- {2..} | string replace -a "\n\t" "\n") ```
1 parent 56fef7c commit 4e379cd

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

shell/key-bindings.fish

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,23 @@ function fzf_key_bindings
6969
if test "$FISH_MAJOR" -gt 2 -o \( "$FISH_MAJOR" -eq 2 -a "$FISH_MINOR" -ge 4 \)
7070
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")
7171
set -lx FZF_DEFAULT_OPTS_FILE ''
72+
73+
# For compatibility with fish versions prior to 3.4.0, `set` should not
74+
# use the `-f | --function` switch, so the FZF_DEFAULT_COMMAND variable
75+
# is set as local, outside the `if` block.
76+
set -lx FZF_DEFAULT_COMMAND
7277
if type -q perl
73-
builtin history -z --reverse | command perl -0 -pe 's/^/$.\t/g; s/\n/\n\t/gm' | eval (__fzfcmd) --tac --read0 --print0 -q '(commandline)' | string replace -r '^\d*\t' '' | read -lz result
74-
and commandline -- $result
78+
set -a FZF_DEFAULT_OPTS '--tac'
79+
set FZF_DEFAULT_COMMAND 'builtin history -z --reverse | command perl -0 -pe \'s/^/$.\t/g; s/\n/\n\t/gm\''
7580
else
76-
set -l h (builtin history -z | string split0)
77-
for i in (seq (count $h) -1 1)
78-
string join0 -- $i\t(string replace -a -- \n \n\t $h[$i] | string collect)
79-
end | eval (__fzfcmd) --read0 --print0 -q '(commandline)' | string replace -r '^\d*\t' '' | read -lz result
80-
and commandline -- $result
81+
set FZF_DEFAULT_COMMAND \
82+
'set -l h (builtin history -z --reverse | string split0);' \
83+
'for i in (seq (count $h) -1 1);' \
84+
'string join0 -- $i\t(string replace -a -- \n \n\t $h[$i] | string collect);' \
85+
'end'
8186
end
87+
eval (__fzfcmd) --read0 --print0 -q '(commandline)' | string replace -r '^\d*\t' '' | read -lz result
88+
and commandline -- $result
8289
else
8390
builtin history | eval (__fzfcmd) -q '(commandline)' | read -l result
8491
and commandline -- $result

0 commit comments

Comments
 (0)