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