From 175e934884566d894a09397b0c63b395e8a40f25 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Tue, 15 Jul 2014 22:41:02 +0100 Subject: [PATCH] Enable ctrl+R history search via peco --- shell/zshrc.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/shell/zshrc.sh b/shell/zshrc.sh index a709488..443240d 100644 --- a/shell/zshrc.sh +++ b/shell/zshrc.sh @@ -85,3 +85,25 @@ zle -N zle-line-init # use ctrl+t to toggle autosuggestions(hopefully this wont be needed as # zsh-autosuggestions is designed to be unobtrusive) bindkey '^T' autosuggest-toggle + + +# +# History search with peco +# + +# Search shell history with peco: https://github.com/peco/peco +# Adapted from: https://github.com/mooz/percol#zsh-history-search +if which peco &> /dev/null; then + function percol_select_history() { + local tac + (which gtac &> /dev/null && tac="gtac") || \ + (which tac &> /dev/null && tac="tac") || \ + tac="tail -r" + BUFFER=$(fc -l -n 1 | eval $tac | peco --query "$LBUFFER") + CURSOR=$#BUFFER # move cursor + zle -R -c # refresh + } + + zle -N percol_select_history + bindkey '^R' percol_select_history +fi