summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorbitraid <bitraid@protonmail.ch>2025-02-15 10:56:01 +0200
committerJunegunn Choi <junegunn.c@gmail.com>2025-02-20 08:30:30 +0900
commit1cf7c0f33404833c02f2a167c599e6f0cd86f72c (patch)
tree95f2b34430005e85064cbbe51e7f240113c567e8 /shell
parentff8ee9ee4e44a476ee575f3869b17a2cd8635b97 (diff)
downloadfzf-1cf7c0f33404833c02f2a167c599e6f0cd86f72c.tar.gz
[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.
Diffstat (limited to 'shell')
-rw-r--r--shell/key-bindings.fish45
1 files changed, 25 insertions, 20 deletions
diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish
index e6fdb19f..7afb8aa2 100644
--- a/shell/key-bindings.fish
+++ b/shell/key-bindings.fish
@@ -52,29 +52,34 @@ function fzf_key_bindings
end
function fzf-history-widget -d "Show command history"
- test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
- begin
- # merge history from other sessions before searching
- test -z "$fish_private_mode"; and builtin history merge
+ set -l fzf_query (commandline | string escape)
- 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_FILE ''
- set -lx FZF_DEFAULT_COMMAND
- set -a -- FZF_DEFAULT_OPTS --with-shell=(status fish-path)\\ -c
+ set -lx FZF_DEFAULT_OPTS (__fzf_defaults '' \
+ '--nth=2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign="\t↳ "' \
+ "--highlight-line --no-multi $FZF_CTRL_R_OPTS --read0 --print0" \
+ "--bind='enter:become:string replace -a -- \n\t \n {2..} | string collect'" \
+ '--with-shell='(status fish-path)\\ -c)
- if type -q perl
- 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 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 | string escape) "--bind=enter:become:'string replace -a -- \n\t \n {2..} | string collect'")
- and commandline -- $result
+ set -lx FZF_DEFAULT_OPTS_FILE
+ set -lx FZF_DEFAULT_COMMAND
+
+ if type -q perl
+ 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 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
+
+ # 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
end