22 lines
506 B
Bash
22 lines
506 B
Bash
# do nothing if fzf is not installed
|
|
(( ! $+commands[fzf] )) && return
|
|
|
|
fzf_history_search() {
|
|
setopt extendedglob
|
|
candidates=(${(f)"$(fc -li -1 0 | fzf +s +m -x -e -q "$BUFFER")"})
|
|
local ret=$?
|
|
if [ -n "$candidates" ]; then
|
|
BUFFER="${candidates[@]/(#m)*/${${(As: :)MATCH}[4,-1]}}"
|
|
BUFFER="${BUFFER[@]/(#b)(?)\\n/$match[1]
|
|
}"
|
|
zle vi-fetch-history -n $BUFFER
|
|
fi
|
|
zle reset-prompt
|
|
return $ret
|
|
}
|
|
|
|
autoload fzf_history_search
|
|
zle -N fzf_history_search
|
|
|
|
bindkey '^r' fzf_history_search
|