Skip to content

Instantly share code, notes, and snippets.

@tarot
Forked from jimeh/zsh-history-search-with-peco.zsh
Last active August 29, 2015 14:18
Show Gist options
  • Save tarot/40a561619bc359f26439 to your computer and use it in GitHub Desktop.
Save tarot/40a561619bc359f26439 to your computer and use it in GitHub Desktop.
# 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 peco_select_history() {
local tac=$( \
(which gtac &> /dev/null && echo -n "gtac") || \
(which tac &> /dev/null && echo -n "tac") || \
echo -n "tail -r" \
)
BUFFER=$(fc -l -n 1 | eval $tac | \
peco --layout=bottom-up --query "$LBUFFER")
CURSOR=$#BUFFER # move cursor
zle -R -c # refresh
}
zle -N peco_select_history
bindkey '^R' peco_select_history
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment