From 6ad924a5ad1dd685b8fc0599a6b2ebd791da8de4 Mon Sep 17 00:00:00 2001 From: kassadin Date: Fri, 10 Sep 2021 16:10:54 +0800 Subject: [PATCH] fix prompt 1. Completion lost prompt 2. Original input is lost when canceling --- zsh-fzf-history-search.zsh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/zsh-fzf-history-search.zsh b/zsh-fzf-history-search.zsh index 295e7d9..ac90172 100644 --- a/zsh-fzf-history-search.zsh +++ b/zsh-fzf-history-search.zsh @@ -4,10 +4,15 @@ fzf_history_search() { setopt extendedglob candidates=(${(f)"$(fc -li -1 0 | fzf +s +m -x -e -q "$BUFFER")"}) - BUFFER="${candidates[@]/(#m)*/${${(As: :)MATCH}[4,-1]}}" - BUFFER="${BUFFER[@]/(#b)(?)\\n/$match[1] + local ret=$? + if [ -n "$candidates" ]; then + BUFFER="${candidates[@]/(#m)*/${${(As: :)MATCH}[4,-1]}}" + BUFFER="${BUFFER[@]/(#b)(?)\\n/$match[1] }" - zle end-of-buffer-or-history + zle vi-fetch-history -n $BUFFER + fi + zle reset-prompt + return $ret } autoload fzf_history_search