From de4c3c7a8a1ab94c9ec2d7aeb37abb8ae4ebb6ed Mon Sep 17 00:00:00 2001 From: MamoruDS Date: Sat, 11 Feb 2023 03:43:30 +0900 Subject: [PATCH 1/2] 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 From 99211d7e405ea5bb261fc2e0b1068eec7092757c Mon Sep 17 00:00:00 2001 From: MamoruDS Date: Sat, 11 Feb 2023 03:54:33 +0900 Subject: [PATCH 2/2] Fix multi-line history to correctly handle line breaks --- zsh-fzf-history-search.zsh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zsh-fzf-history-search.zsh b/zsh-fzf-history-search.zsh index 9dde3cc..7eaf9fd 100644 --- a/zsh-fzf-history-search.zsh +++ b/zsh-fzf-history-search.zsh @@ -64,8 +64,7 @@ fzf_history_search() { else BUFFER="${candidates[@]}" fi - BUFFER="${BUFFER[@]/(#b)(?)\\n/$match[1] -}" + BUFFER=$(printf "${BUFFER[@]//\\\\n/\\\\\\n}") zle vi-fetch-history -n $BUFFER if [ -n "${ZSH_FZF_HISTORY_SEARCH_END_OF_LINE}" ]; then zle end-of-line