From e45f1c9997c041ec46ec7000f4b4e537eff22ac7 Mon Sep 17 00:00:00 2001 From: sev Date: Thu, 17 Oct 2024 23:59:25 -0500 Subject: [PATCH] zsh: replace ^R with fzf if it exists --- etc/zsh/.zshrc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/etc/zsh/.zshrc b/etc/zsh/.zshrc index 90e15a0..4d88417 100644 --- a/etc/zsh/.zshrc +++ b/etc/zsh/.zshrc @@ -200,9 +200,19 @@ for k v (${(kv)a}) { } unset a k v -## other binds +## fzf # bash-style reverse-search-history (i.e. reverse-i-search) -bindkey '^R' history-incremental-pattern-search-backward +if [[ -v commands[fzf] ]] { + function _history-incremental-pattern-search-fzf { + l=(${(f)"$(fc -li -1 0 | fzf -emn 1 +s --preview-window=hidden ${BUFFER:+-q $BUFFER})"}) + l=$(for x ("${l[@]}") { echo ${${=x}:3}; }) + BUFFER="$l" + } + zle -N _history-incremental-pattern-search-fzf + bindkey '^R' _history-incremental-pattern-search-fzf +} else { + bindkey '^R' history-incremental-pattern-search-backward +} ### aliases ## builtins -- 2.47.0