From 66adff9257c0bdcf5fea357cf4afd9c5804ac9d9 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Wed, 23 Dec 2020 23:40:35 +0530 Subject: Moves zsh config to config and symlinked --- config/zsh/plugins/fzf-history.zsh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 config/zsh/plugins/fzf-history.zsh (limited to 'config/zsh/plugins/fzf-history.zsh') diff --git a/config/zsh/plugins/fzf-history.zsh b/config/zsh/plugins/fzf-history.zsh new file mode 100644 index 0000000..f91cc99 --- /dev/null +++ b/config/zsh/plugins/fzf-history.zsh @@ -0,0 +1,19 @@ +full_history() { + [[ ${@[-1]-} = *[0-9]* ]] && builtin fc -l "$@" || builtin fc -l "$@" 1; +} + +trim() { sed 's/^\s*//g'; } +reverse() { sed -n '1!G;h;$p'; } +unique() { awk '!seen[$0]++'; } + +search_history() { + local result=$(full_history | trim | cut -d' ' -f 2- | reverse | unique | fzf); + + # Replace the buffer with the editor output. + print -Rz - "$(echo -n "$result" | trim)"; + + zle send-break # Force reload from the buffer stack +} + +zle -N search_history; +bindkey '^R' search_history; -- cgit v1.3.1