From daf2367e9d1035aa3d9e4c7acd7a29fff3a3633d Mon Sep 17 00:00:00 2001 From: Stefan Hojer Date: Tue, 31 Aug 2021 01:29:18 +0200 Subject: [PATCH 1/3] feat: use `fc` instead of `history` --- zsh-fzf-history-search.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh-fzf-history-search.zsh b/zsh-fzf-history-search.zsh index af97444..5bce856 100644 --- a/zsh-fzf-history-search.zsh +++ b/zsh-fzf-history-search.zsh @@ -1,6 +1,6 @@ fzf_history_seach() { setopt extendedglob - candidates=(${(f)"$(history -t '%Y-%m-%d %H:%M:%S' 0| fzf +s +m -x --tac -e -q "$BUFFER")"}) + 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] }" From 0bf9432bda87af8a3bf38b6cfec09b85c641d99f Mon Sep 17 00:00:00 2001 From: Stefan Hojer Date: Tue, 31 Aug 2021 01:51:11 +0200 Subject: [PATCH 2/3] feat: disable plugin if fzf is not installed --- zsh-fzf-history-search.zsh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/zsh-fzf-history-search.zsh b/zsh-fzf-history-search.zsh index 5bce856..295e7d9 100644 --- a/zsh-fzf-history-search.zsh +++ b/zsh-fzf-history-search.zsh @@ -1,4 +1,7 @@ -fzf_history_seach() { +# 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")"}) BUFFER="${candidates[@]/(#m)*/${${(As: :)MATCH}[4,-1]}}" @@ -7,7 +10,7 @@ fzf_history_seach() { zle end-of-buffer-or-history } -autoload fzf_history_seach -zle -N fzf_history_seach +autoload fzf_history_search +zle -N fzf_history_search -bindkey '^r' fzf_history_seach +bindkey '^r' fzf_history_search From 6468cddfe5bb8207cd1838291c8eebe4d86bd18d Mon Sep 17 00:00:00 2001 From: Stefan Hojer Date: Tue, 31 Aug 2021 02:09:15 +0200 Subject: [PATCH 3/3] feat: add *.plugin.zsh (backwards compatible) --- zsh-fzf-history-search.plugin.zsh | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 zsh-fzf-history-search.plugin.zsh diff --git a/zsh-fzf-history-search.plugin.zsh b/zsh-fzf-history-search.plugin.zsh new file mode 100644 index 0000000..13ae8e1 --- /dev/null +++ b/zsh-fzf-history-search.plugin.zsh @@ -0,0 +1,2 @@ +0=${(%):-%N} +source ${0:A:h}/zsh-fzf-history-search.zsh