Files
zsh-fzf-history-search/zsh-fzf-history-search.zsh
kassadin 6ad924a5ad fix prompt
1. Completion lost prompt
2. Original input is lost when canceling
2021-09-10 16:19:36 +08:00

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