]> git.sev.monster Git - dotfiles.git/commitdiff
zsh: replace ^R with fzf if it exists
authorsev <git@sev.monster>
Fri, 18 Oct 2024 04:59:25 +0000 (23:59 -0500)
committersev <git@sev.monster>
Fri, 18 Oct 2024 05:01:06 +0000 (00:01 -0500)
etc/zsh/.zshrc

index 90e15a0c6f6c0a675884aa662152bc9bca25d842..4d884178d000a56fe5279047fe7942561e609276 100644 (file)
@@ -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
This page took 0.04669 seconds and 4 git commands to generate.