[fish] Refactor fzf-history-widget

- Remove check/set of FZF_TMUX_HEIGHT variable. It is already done by
  __fzf_defaults.
- Remove unnecessary begin/end block.
- Pass all fzf options (except query) through FZF_DEFAULT_OPTS variable.
This commit is contained in:
bitraid
2025-02-15 10:56:01 +02:00
committed by Junegunn Choi
parent ff8ee9ee4e
commit 1cf7c0f334

View File

@@ -52,29 +52,34 @@ function fzf_key_bindings
end end
function fzf-history-widget -d "Show command history" function fzf-history-widget -d "Show command history"
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40% set -l fzf_query (commandline | string escape)
begin
# merge history from other sessions before searching
test -z "$fish_private_mode"; and builtin history merge
set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"\t"↳ ' --highlight-line +m $FZF_CTRL_R_OPTS") set -lx FZF_DEFAULT_OPTS (__fzf_defaults '' \
set -lx FZF_DEFAULT_OPTS_FILE '' '--nth=2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign="\t↳ "' \
set -lx FZF_DEFAULT_COMMAND "--highlight-line --no-multi $FZF_CTRL_R_OPTS --read0 --print0" \
set -a -- FZF_DEFAULT_OPTS --with-shell=(status fish-path)\\ -c "--bind='enter:become:string replace -a -- \n\t \n {2..} | string collect'" \
'--with-shell='(status fish-path)\\ -c)
if type -q perl set -lx FZF_DEFAULT_OPTS_FILE
set -a FZF_DEFAULT_OPTS '--tac' set -lx FZF_DEFAULT_COMMAND
set FZF_DEFAULT_COMMAND 'builtin history -z --reverse | command perl -0 -pe \'s/^/$.\t/g; s/\n/\n\t/gm\''
else if type -q perl
set FZF_DEFAULT_COMMAND \ set -a FZF_DEFAULT_OPTS '--tac'
'set -l h (builtin history -z --reverse | string split0);' \ set FZF_DEFAULT_COMMAND 'builtin history -z --reverse | command perl -0 -pe \'s/^/$.\t/g; s/\n/\n\t/gm\''
'for i in (seq (count $h) -1 1);' \ else
'string join0 -- $i\t(string replace -a -- \n \n\t $h[$i] | string collect);' \ set FZF_DEFAULT_COMMAND \
'end' 'set -l h (builtin history -z --reverse | string split0);' \
end 'for i in (seq (count $h) -1 1);' \
set -l result (eval $FZF_DEFAULT_COMMAND \| (__fzfcmd) --read0 --print0 -q (commandline | string escape) "--bind=enter:become:'string replace -a -- \n\t \n {2..} | string collect'") 'string join0 -- $i\t(string replace -a -- \n \n\t $h[$i] | string collect);' \
and commandline -- $result 'end'
end end
# Merge history from other sessions before searching
test -z "$fish_private_mode"; and builtin history merge
set -l result (eval $FZF_DEFAULT_COMMAND \| (__fzfcmd) --query=$fzf_query)
and commandline -- $result
commandline -f repaint commandline -f repaint
end end