From de4c3c7a8a1ab94c9ec2d7aeb37abb8ae4ebb6ed Mon Sep 17 00:00:00 2001 From: MamoruDS Date: Sat, 11 Feb 2023 03:43:30 +0900 Subject: [PATCH] Fix candidate parsing now preserving original history content The previous expansion condensed repeated white spaces which caused harm to the original history content. --- zsh-fzf-history-search.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zsh-fzf-history-search.zsh b/zsh-fzf-history-search.zsh index e36efe1..9dde3cc 100644 --- a/zsh-fzf-history-search.zsh +++ b/zsh-fzf-history-search.zsh @@ -59,7 +59,11 @@ fzf_history_search() { candidates=(${(f)"$(eval $history_cmd | fzf ${=ZSH_FZF_HISTORY_SEARCH_FZF_ARGS} ${=ZSH_FZF_HISTORY_SEARCH_FZF_EXTRA_ARGS} -q "$BUFFER")"}) local ret=$? if [ -n "$candidates" ]; then - BUFFER="${candidates[@]/(#m)*/${${(As: :)MATCH}[${CANDIDATE_LEADING_FIELDS},-1]}}" + if (( ! $CANDIDATE_LEADING_FIELDS == 1 )); then + BUFFER="${candidates[@]/(#m)[0-9 \-\:]##/${${(As: :)MATCH}[${CANDIDATE_LEADING_FIELDS},-1]}}" + else + BUFFER="${candidates[@]}" + fi BUFFER="${BUFFER[@]/(#b)(?)\\n/$match[1] }" zle vi-fetch-history -n $BUFFER